类型错误:float() 参数必须是字符串或数字,而不是“datetime.time”
我有一个看起来像这样的 DataFrame:
df_11=
dataReceived time_diff3 time
0 1 76.356133 15:00:56.052554
1 1 68.195077 15:02:18.764644
2 1 141.308039 15:03:38.039307
3 1 48.674365 15:06:22.955319
4 1 113.261287 15:07:57.382506
... ... ... ... ... ...
6050 1 18.000000 02:43:10
6051 1 18.000000 02:43:28
6052 1 19.000000 02:43:46
6053 1 18.000000 02:44:05
6054 1 0.000000 02:44:23
我想绘制:
ax1 = df_11.plot(kind='scatter', x='time', y='time_diff3', color='r')
print(ax1)
并且出现以下错误:
TypeError: float() argument must be a string or a number, not 'datetime.time'
我不明白为什么我无法绘制此图,因为列 time
是 datetime.time.我该如何将 datetime.time 转换为 datetime64?
I have a DataFrame that looks like this:
df_11=
dataReceived time_diff3 time
0 1 76.356133 15:00:56.052554
1 1 68.195077 15:02:18.764644
2 1 141.308039 15:03:38.039307
3 1 48.674365 15:06:22.955319
4 1 113.261287 15:07:57.382506
... ... ... ... ... ...
6050 1 18.000000 02:43:10
6051 1 18.000000 02:43:28
6052 1 19.000000 02:43:46
6053 1 18.000000 02:44:05
6054 1 0.000000 02:44:23
I want to plot :
ax1 = df_11.plot(kind='scatter', x='time', y='time_diff3', color='r')
print(ax1)
And I got the following error:
TypeError: float() argument must be a string or a number, not 'datetime.time'
I dont understand why I cant plot this graph, since column time
is datetime.time
. How am I supposed to convert datetime.time to datetime64?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用
to_datetime
将“time”列强制转换为日期时间,并使用dt.strftime
提取时间部分。您可能需要旋转标签:You could coerce "time" column to datetime using
to_datetime
and extract the time component usingdt.strftime
. You may want to rotate the labels: