TimeSeries用Bokeh绘制

时间:2016-08-18 19:02:02

标签: python datetime pandas plot bokeh

从BOKEH MAINTAINER注意:包含bokeh.charts的{​​{1}} API在很久以前就已被弃用和删除。此问题与Bokeh的任何近期或未来版本无关。要绘制时间序列,请使用稳定且受支持的TimeSeries API。一些示例可以是found here

我正在尝试用类别绘制bokeh.plotting图。

xaxis_values:Timeseries yaxis_values:startTIme

groupby:count

每天都有24小时的数据集,像这样整个数据集超过100天,我试图找到几种类型的图。

  1. day分组并汇总day每小时的所有counts 这将在一个图表中给出7个时间序列图。

  2. 按天分开,即每startTime个等等,无论天数mon, tue, wed如何,并绘制24小时的时间序列。

  3. 按小时分组,不论日期。即n等等

  4. 通过散景或海啸获得更好的可视化效果的最佳方法是什么?

    输入:

    00:00:00, 01:00:00

    代码:参考:Here

    2004-01-05,22:00:00,23:00:00,Mon,18944,790
    2004-01-05,23:00:00,00:00:00,Mon,17534,750
    2004-01-06,00:00:00,01:00:00,Tue,17262,747
    2004-01-06,01:00:00,02:00:00,Tue,19072,777
    2004-01-06,02:00:00,03:00:00,Tue,18275,785
    2004-01-06,03:00:00,04:00:00,Tue,13589,757
    2004-01-06,04:00:00,05:00:00,Tue,16053,735
    2004-01-06,05:00:00,06:00:00,Tue,11440,636
    2004-01-06,06:00:00,07:00:00,Tue,5972,513
    2004-01-06,07:00:00,08:00:00,Tue,3424,382
    2004-01-06,08:00:00,09:00:00,Tue,2696,303
    2004-01-06,09:00:00,10:00:00,Tue,2350,262
    2004-01-06,10:00:00,11:00:00,Tue,2309,254
    

    错误:

    import numpy as np
    import pandas as pd
    from bokeh.charts import TimeSeries, show, output_file, vplot
    
    output_file("timeseries.html")
    
    data_one = pd.read_csv('one_hour.csv')
    data_one.columns = ['date', 'startTime', 'endTime', 'day', 'count', 'unique']
    
    data = dict(data_one=data_one['count'])
    
    tsline = TimeSeries(data,
        x='startTime', y='count',
        color=['day'], title="Timeseries", ylabel='count', legend=True)
    
    show(vplot(tsline))
    

    编辑:更改后

    Traceback (most recent call last):
      File "date_graph.py", line 10, in <module>
        data = dict(data_one=data_one['count'])
      File "/usr/local/lib/python2.7/dist-packages/pandas/core/frame.py", line 1997, in __getitem__
        return self._getitem_column(key)
      File "/usr/local/lib/python2.7/dist-packages/pandas/core/frame.py", line 2004, in _getitem_column
        return self._get_item_cache(key)
      File "/usr/local/lib/python2.7/dist-packages/pandas/core/generic.py", line 1350, in _get_item_cache
        values = self._data.get(item)
      File "/usr/local/lib/python2.7/dist-packages/pandas/core/internals.py", line 3290, in get
        loc = self.items.get_loc(item)
      File "/usr/local/lib/python2.7/dist-packages/pandas/indexes/base.py", line 1947, in get_loc
        return self._engine.get_loc(self._maybe_cast_indexer(key))
      File "pandas/index.pyx", line 137, in pandas.index.IndexEngine.get_loc (pandas/index.c:4154)
      File "pandas/index.pyx", line 159, in pandas.index.IndexEngine.get_loc (pandas/index.c:4018)
      File "pandas/hashtable.pyx", line 675, in pandas.hashtable.PyObjectHashTable.get_item (pandas/hashtable.c:12368)
      File "pandas/hashtable.pyx", line 683, in pandas.hashtable.PyObjectHashTable.get_item (pandas/hashtable.c:12322)
    KeyError: 'count
    

    错误:

    data = dict(data_one=data_one['count'].tolist())
    

0 个答案:

没有答案