0

我有一个带有日期时间索引的数据框。我正在尝试使用 Holoview Histogram 函数生成直方图:

df
dt, avg_val
2015-07-07, 20.3
2015-07-08, 20.4
2015-07-09, 10.3
...

df.index
DatetimeIndex(['2015-07-07', '2015-07-08', '2015-07-09', '2015-07-10',
           '2015-07-11', '2015-07-12', '2015-07-13', '2015-07-14',
           '2015-07-15', '2015-07-16',
           ...
           '2017-03-15', '2017-03-16', '2017-03-17', '2017-03-18',
           '2017-03-19', '2017-03-20', '2017-03-21', '2017-03-22',
           '2017-03-23', '2017-03-24'],
          dtype='datetime64[ns]', name='dt', length=627, freq=None)

hv_d = hv.Dataset(df.reset_index(), kdims=['dt'])
hv.Histogram(hv_d)
TypeError: ufunc 'absolute' did not contain a loop with signature matching types dtype('<M8[ns]') dtype('<M8[ns]')

如何创建此直方图?

4

1 回答 1

0

Holoview 的直方图示例显示使用np.histogram(),因此它看起来像这样:

图片

dts = pd.date_range('2015-07-07', '2015-07-14')
df = pd.DataFrame(data={'avg_val': [4, 4, 3, 2, 1, 2, 4, 4]}, index=dts)
frequencies, edges = np.histogram(df['avg_val'], 20)
hv.Histogram((frequencies, edges))
于 2018-02-11T01:34:01.350 回答