在seaborn中绘制datetime.time

时间:2018-09-12 07:20:36

标签: python pandas matplotlib seaborn

嗨,我在与seaborn约会时遇到了麻烦。我试图用x作为数据类型class NetworkRequest<T: Codable> { var objectClass: T.Type! init(objectClass : T.Type) { self.objectClass = objectClass } } class Person : Codable { var name:String? } let request = NetworkRequest<Person>(objectClass: Person.self) let response : Dictionary<String,Any> = ["name":"test"] let data : Data = try! JSONSerialization.data(withJSONObject: response,options: []) do { let person = try JSONDecoder().decode(request.objectClass, from: data) print(person.name ?? "--") } catch { print(error) } 绘制分类数据,但出现以下错误:

datetime.time

这是我的df:

float() argument must be a string or a number, not 'datetime.time'

这是我的代码:

       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

更新:

'toronto_time'的

dtype是一个对象。当我使用pd.to_datetime时,它将转换为datetime,但是会添加一个日期。

1 个答案:

答案 0 :(得分:1)

如果我对您的理解正确,则可以采用以下方式:

import matplotlib.pyplot as plt
import seaborn as sns
df['toronto_time'] = pd.to_datetime(df['toronto_time']).dt.strftime('%H:%M:%S')
sns.scatterplot(df['toronto_time'], df['description'])
plt.show()

enter image description here