相关疑难解决方法(0)

Pandas类型错误试图绘图

我正在尝试基于Pandas数据帧创建基本散点图.但是当我调用分散例程时,我收到错误"TypeError:invalid type promotion".重现问题的示例代码如下所示:

t1 = pd.to_datetime('2015-11-01 00:00:00')
t2 = pd.to_datetime('2015-11-02 00:00:00')

Time = pd.Series([t1, t2])
r = pd.Series([-1, 1])

df = pd.DataFrame({'Time': Time, 'Value': r})
print(df)

print(type(df.Time))
print(type(df.Time[0]))

fig = plt.figure(figsize=(x_size,y_size))
ax = fig.add_subplot(111)
ax.scatter(df.Time, y=df.Value, marker='o')
Run Code Online (Sandbox Code Playgroud)

结果输出是

        Time  Value
0 2015-11-01     -1
1 2015-11-02      1
<class 'pandas.core.series.Series'>
<class 'pandas.tslib.Timestamp'>

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-285-f4ed0443bf4d> in <module>()
     15 fig = plt.figure(figsize=(x_size,y_size))
     16 ax = fig.add_subplot(111)
---> 17 ax.scatter(df.Time, y=df.Value, marker='o')

C:\Anaconda3\lib\site-packages\matplotlib\axes\_axes.py in scatter(self, x,    y, s, c, …
Run Code Online (Sandbox Code Playgroud)

python matplotlib pandas

18
推荐指数
4
解决办法
2万
查看次数

标签 统计

matplotlib ×1

pandas ×1

python ×1