2017-10-02 5 views
1

私はpandas autocorrelation_plot()関数をSQL結果のデータで満たしたデータフレームで使用しようとしていますが、このコードを実行します。パンダ "TypeError:+: 'Timedelta'と 'float'のためのサポートされていないオペランドタイプ"

import MySQLdb 
import pandas as pd 
from matplotlib import pyplot 
from pandas.tools.plotting import autocorrelation_plot 
connection = MySQLdb.connect(host = "host", user = "user", passwd = "passwd", db = "db") 
exect = connection.cursor() 
query = "query" 
exect.execute(query) 
frame = pd.read_sql(query, con=connection) 
connection.close() 
print(frame.head()) 
autocorrelation_plot(frame) 
pyplot.show() 

私は問題なくフレームを印刷することができますが、私はautocorrelation_plot()関数を使用しようとすると、私はこのエラーを取得します。私のデータフレームの出力はこれです:

time  value 
0 00:00:14 283.80 
1 00:01:14 271.97 
2 00:02:14 320.53 
3 00:03:14 346.78 
4 00:04:14 280.72 
5 00:05:14 277.41 
6 00:06:14 308.65 
7 00:07:14 321.27 
8 00:08:14 320.68 
9 00:09:14 332.32 
+0

あなたがやろうとしているか知っていますか? –

+0

私はフレームの値を印刷するときにこのような時系列から自動相関をプロットしようとしています 0 00:00:14 283.80 1 00:01:14 271.97 2 00:02: 14 320.53 3 00:03:14 346.78 4 00:04:14 280.72 –

+0

'df.head(10)'を印刷してここに投稿してください。 –

答えて

0

あなたはプロットする前にインデックスとしてtime設定する​​を使用しての恩恵を受ける可能性があります。

from pandas.plotting import autocorrelation_plot 

df  
     time value 
0 00:00:14 283.80 
1 00:01:14 271.97 
2 00:02:14 320.53 
3 00:03:14 346.78 
4 00:04:14 280.72 
5 00:05:14 277.41 
6 00:06:14 308.65 
7 00:07:14 321.27 
8 00:08:14 320.68 
9 00:09:14 332.32 

df.dtypes  
time  timedelta64[ns] 
value   float64 
dtype: object 

autocorrelation_plot(df.set_index('time')) 
plt.show() 

enter image description here

関連する問題