Python 无法使用内置绘图仪打印数据帧
我有以下数据帧:Python 无法使用内置绘图仪打印数据帧,python,pandas,plot,Python,Pandas,Plot,我有以下数据帧: created_date client_name amount timestamp 0 2019-03-17 08:48:36 ABC 156.89 2019-03-17 08:48:36 1 2019-03-17 08:48:13 ABC 563.62 2019-03-17 08:48:13 2 2019-03-17 08:47:45 ABC 126.92 2019-03-17 08:4
created_date client_name amount timestamp
0 2019-03-17 08:48:36 ABC 156.89 2019-03-17 08:48:36
1 2019-03-17 08:48:13 ABC 563.62 2019-03-17 08:48:13
2 2019-03-17 08:47:45 ABC 126.92 2019-03-17 08:47:45
3 2019-03-16 13:58:11 XYZ 292.71 2019-03-16 13:58:11
4 2019-03-16 10:01:28 EFG 180.41 2019-03-16 10:01:28
当我尝试使用内置的plot()
方法时:
ax = df.loc[df.client_name == 'ABC'].plot(x=['timestamp'], y=['amount'])
我得到以下错误:
ValueError: x must be a label or position
我以前用过Bokeh,但现在我必须用内置绘图仪。正确的方法是什么?正如@JohanC所指出的,
df['amount']
不是一个干净的float
,其中有一些字符串,因此打印(df['amount'])
测试返回一个对象。一旦解决了这个问题,最初的解决方案就奏效了:
ax = df.loc[df.client_name == 'ABC'].plot(x='timestamp', y='amount')
时间戳
列被转换为正确的日期和时间。您可以尝试。不带方括号的绘图(x='timestamp',y='amount')
。然后我得到类型错误:没有要绘图的数字数据
我怀疑这是因为索引,我想我可以将时间戳输入索引,但我想知道是否有更干净的方法。尝试打印(df['amount'])
并检查它是否为dtype:float64。如果是object,则需要转换amount列<代码>df['amount']=df['amount'].aType(浮动)