使用Holoviews绘制表格数据

3
我想绘制这样的数据。
 |   |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包。

我正在尝试创建多个像这样的小部件:

                                               下拉菜单(主机名)
线型图(abstime vs cpu)                    下拉菜单(类型)
按id着色
                                              下拉菜单(主机名)
线型图(abstime vs cpu)                     下拉菜单(类型)
                                               下拉菜单(id)
线型图(abstime vs cpu)                      下拉菜单(主机名)
按类型着色

我认为最理想的方法是使用类似于hv.Table的东西,然后使用Holoviews的.to.curve和其他技术来对其进行分组和处理。

我正在尝试遵循示例和教程 - 但它们中没有任何列的重复,所以我不知道如何分组,我的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 Dataframe(许多CSV文件),所以如果有影响,我会依赖延迟计算...
谢谢!

1
这似乎是HoloViews中的一个简单的打字错误,我已经为此做出了修复:https://github.com/ioam/holoviews/pull/1593该修复将在下一个版本中提供,即HoloViews 1.8,并且将在今天稍后发布的1.8dev3版本中可用,可通过“conda install -c ioam/label/dev holoviews”进行安装。 - philippjfr
1个回答

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的曲线。如果您的数据有多种类型,则还会有第二个下拉小部件。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接