【发布时间】:2019-02-16 18:21:01
【问题描述】:
您好,我无法使用 seaborn 绘制日期时间。我正在尝试使用 x 作为数据类型 datetime.time 绘制分类数据,但出现以下错误:
float() argument must be a string or a number, not 'datetime.time'
这是我的 df:
toronto_time description
0 00:00:50 STATS
1 00:01:55 STATS
2 00:02:18 ONLINE
3 00:05:24 STATS
4 00:05:34 STATS
5 00:06:33 OFFLINE
这是我的代码:
import matplotlib.pyplot as plt
import seaborn as sns
plt.style.use('seaborn-colorblind')
plt.figure(figsize=(8,6))
sns.swarmplot('toronto_time', 'description', data=df);
plt.show()
更新:
'toronto_time' 的 dtype 是一个对象。当我使用 pd.to_datetime 时,它会转换为 datetime,但是会添加一个日期。
【问题讨论】:
-
此解决方案stackoverflow.com/a/57148021 也适用于当前问题。
标签: python pandas matplotlib seaborn