使用全息视图绘制表格数据

时间:2017-06-21 03:37:48

标签: python csv plot dask 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 PLOTS ( abstime vs cpu )                  DROPDOWN (type)
colored by id
                                               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'

高度赞赏任何相关的例子!

BTW,我的表df是Dask Dataframe(很多CSV文件),所以如果重要的话,我会依赖延迟计算......

谢谢!

1 个答案:

答案 0 :(得分: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

我使用Pandas而不是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的曲线。如果您的数据有多种类型,那么还会有第二个下拉小部件。