2

私のデータは次の形式です。

datetime, count
2011-01-01 00:00:00, 10
2011-01-01 01:00:00, 15
2011-01-01 02:00:00, 20
...

ggplot を使用して、次の 2 つのグラフをプロットします。

  1. 経時的なカウントの変化
  2. 日ごとのカウントの変化

文字列をパンダの日時に変換することで、最初のものをプロットできました

csv_file['datetime'] = pd.to_datetime(csv_file['datetime'])

そして、ggplot を使用してプロットします。

2つ目は、datetimeをtimeに変換しました

csv_file['time'] = csv_file['datetime'].map(methodcaller('time'))

type(csv_file['time'][4]) = <type 'datetime.time'>

しかし、プロット中に、次のエラーが発生します。

File "/Library/Python/2.7/site-packages/numpy-1.9.0.dev_297f54b-py2.7-macosx-10.9-intel.egg/numpy/core/numeric.py", line 460, in asarray
    return array(a, dtype, copy=False, order=order)
TypeError: float() argument must be a string or a number

プロット コード:

ggplot1 =  ggplot(aes(x='time', y='count'), data=csv_file) + \
        geom_point(color='lightblue') + \
        stat_smooth(span=.15, color='black', se=True) + \
        ggtitle("Test") + \
        xlab("time") + \
        ylab("count")

    ggplot1.draw() 

頭:

     datetime                time        count
0 2011-01-01 00:00:00      00:00:00       39
1 2011-01-01 01:00:00      01:00:00       40 
2 2011-01-01 02:00:00      02:00:00       10  
3 2011-01-01 03:00:00      03:00:00       14
4 2011-01-01 04:00:00      04:00:00       18

完全なスタック トレース:

File "hello.py", line 43, in <module>
    run()
  File "hello.py", line 41, in run
    ggplot1.draw()    
  File "/Library/Python/2.7/site-packages/ggplot/ggplot.py", line 305, in draw
    callbacks = geom.plot_layer(data, ax)
  File "/Library/Python/2.7/site-packages/ggplot/geoms/geom.py", line 115, in plot_layer
    data = self._calculate_stats(data)
  File "/Library/Python/2.7/site-packages/ggplot/geoms/geom.py", line 275, in _calculate_stats
    new_data = self._stat._calculate(data)
  File "/Library/Python/2.7/site-packages/ggplot/stats/stat_smooth.py", line 43, in _calculate
    x, y, y1, y2 = smoothers.lowess(x, y, span=span)
  File "/Library/Python/2.7/site-packages/ggplot/components/smoothers.py", line 53, in lowess
    result = smlowess(np.array(y), np.array(x), frac=span)
  File "/Library/Python/2.7/site-packages/statsmodels-0.6.0-py2.7-macosx-10.9-intel.egg/statsmodels/nonparametric/smoothers_lowess.py", line 128, in lowess
    exog = np.asarray(exog, float)
  File "/Library/Python/2.7/site-packages/numpy-1.9.0.dev_297f54b-py2.7-macosx-10.9-intel.egg/numpy/core/numeric.py", line 460, in asarray
    return array(a, dtype, copy=False, order=order)
TypeError: float() argument must be a string or a number
4

0 に答える 0