2017-06-21 35 views
2

表格數據,我想畫出這樣繪圖與holoviews

| |abstime    |hostname |type |id |cpu |mem |reltime| 
----------------------------------------------------------------------------- 
|0 |2017-06-21 02:45:39 |hw03  |ps  |0 |16.0 |0.0 |0:00.08| 
|1 |2017-06-21 02:45:43 |hw03  |ps  |0 |98.0 |0.1 |0:02.23| 
|2 |2017-06-21 02:45:48 |hw03  |ps  |0 |1591.0 |0.1 |0:21.09| 
|3 |2017-06-21 02:45:52 |hw03  |ps  |0 |0.0 |0.1 |0:38.35| 
|4 |2017-06-21 02:45:57 |hw03  |ps  |0 |0.0 |0.1 |1:01.41| 
使用Holoviews Python包

數據。

我試圖創建多個小部件是這樣的:

​​
 
               DROPDOWN (hostname) 
LINE PLOT (abstime vs cpu)     DROPDOWN (type) 
               DROPDOWN (id) 
 
LINE PLOT (abstime vs cpu)     DROPDOWN (hostname) 
colored by type 

我認爲最好是使用像hv.Table,然後切片,用.to.curve和其他技術骰子這Holoviews。

我試圖按照示例和教程 - 但他們都沒有在列重複,所以我混淆如何分組,什麼都要我kdims,vdims和cdims ...

對於防爆。 :

table=hv.Table(df,kdims=['abstime','reltime','hostname','type','id'],vdims=['cpu','mem']) 

print(table) 
#:Table [abstime,reltime,hostname,type,id] (cpu,mem) 

table[None,None,{'hw03'},{'ps'},None].to.curve('abstime','cpu') 

這給了我一個錯誤在最後一次通話:

AttributeError: 'DataFrame' object has no attribute 'itertuple' 

任何相關的例子不勝感激!

順便說一句,我的表df是DASK數據框(許多CSV文件),所以我依靠延遲計算,如果該事項...

謝謝!

+0

這似乎是HoloViews中的一個簡單的錯字,我已經在此處進行了修復:https://github.com/ioam/holoviews/pull/1593 該修復程序將在下一個版本中提供,這是HoloViews 1.8,將在今天晚些時候在1.8dev3版本中使用''conda install -c ioam/label/dev holoviews''安裝。 – philippjfr

回答

0

要獲得下拉我擴展數據集,包括與其他主機名稱記錄:

 
|abstime   |hostname|type|id|cpu |mem| reltime 
0| 2017-06-2102:45:39|hw03 |ps |0 |16.0 |0.0| 0:00.08 
1| 2017-06-2102:45:43|hw03 |ps |0 |98.0 |0.1| 0:02.23 
2| 2017-06-2102:45:48|hw03 |ps |0 |1591.0|0.1| 0:21.09 
3| 2017-06-2102:45:52|hw03 |ps |0 |0.0 |0.1| 0:38.35 
4| 2017-06-2102:45:57|hw04 |ps |0 |0.0 |0.1| 1:01.41 
5| 2017-06-2102:45:39|hw04 |ps |0 |16.0 |0.0| 0:00.08 
6| 2017-06-2102:45:43|hw04 |ps |0 |98.0 |0.1| 0:02.23 
7| 2017-06-2102:45:48|hw04 |ps |0 |1591.0|0.1| 0:21.09 
8| 2017-06-2102:45:52|hw04 |ps |0 |0.0 |0.1| 0:38.35 
9| 2017-06-2102:45:57|hw04 |ps |0 |0.0 |0.1| 1:01.41 

我使用的是熊貓,而不是DASK,但原理是一樣的:

import pandas as pd 
import holoviews as hv 
hv.extension('bokeh') 
d=pd.read_csv('so.csv') 
# Create a holoviews dataset from any of a number of data structures. 
ds=hv.Dataset(d) 
display(ds.data) 
#Now create a table from just the columns that we want. Otherwise 
#You will get more dropdowns than you might want in the holomap. 
tb=hv.Table(ds,kdims=['abstime','hostname','type'],vdims='cpu') 
display(tb) 
#This is a dimensioned element. 
hv.HoloMap(tb.to.curve(kdims=['abstime'],vdims='cpu')) 

這會給你一個主機名的下拉菜單,並顯示abstime和cpu的曲線。如果您的數據有多個類型,那麼還會有第二個下拉小部件。