Python 熊猫";TypeError:+;的操作数类型不受支持:';时间差';和';浮动'&引用;
我试图使用pandas autocorrelation_plot()函数和sql结果填充的数据帧,但在运行此代码时,我不断遇到此错误:Python 熊猫";TypeError:+;的操作数类型不受支持:';时间差';和';浮动'&引用;,python,pandas,matplotlib,dataframe,plot,Python,Pandas,Matplotlib,Dataframe,Plot,我试图使用pandas autocorrelation_plot()函数和sql结果填充的数据帧,但在运行此代码时,我不断遇到此错误: import MySQLdb import pandas as pd from matplotlib import pyplot from pandas.tools.plotting import autocorrelation_plot connection = MySQLdb.connect(host = "host", user = "user", pas
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
使用
set_index
将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()
你知道你想做什么吗?我正试图从一个时间序列中绘制自相关性,当我打印frame:0 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打印
df.head(10)
并将其张贴在这里时,它看起来像这样。