【发布时间】:2016-12-06 20:28:23
【问题描述】:
我想将以下矩阵除以 60(将其转换为秒),然后绘制 heatmap 以查看密度。
Zone1 Zone2 Zone3 Zone4
2016-05-13_2 71 0 182 36
2016-05-14_3 94 0 0 68
2016-05-14_4 5 0 50 29
2016-05-17_5 0 101 0 36
2016-05-18_10 0 120 0 106
2016-05-18_11 62 0 784 3668
2016-05-18_12 0 330 0 19
我必须将其转换为列表值,然后除以 60
import pandas as pd
import plotly.plotly as py
df2=(df.values/60)
df3=list(df2)
py.iplot(df3, filename='basic-heatmap')
PlotlyError: The `figure_or_data` positional argument must be either `dict`-like or `list`-like.
请告诉我哪里出错了
【问题讨论】:
-
不是
df3=list(df2)而不是df3=list(df3)吗? -
是的..这是一个错字。编辑它
-
你的 df3 实际上是一个 numpy 数组的列表。你可能想试试
df3 = df2.to_dict('dict')或df3 = df2.to_dict('list')。 (我不能肯定地说 b/c 我不知道究竟在哪里寻找什么。)您也可以使用 seaborn 包直接从数据框生成热图,而不是转换为列表或字典。
标签: python pandas plot heatmap divide