[英]Change a number represented as an object to a long or other format within dataframe
因此,我正在使用python 3.6.5,并具有如下所示的数据框,但尺寸更大。
Date Open High Low Close Volume
0 2018-04-16 8337.57 8371.15 7925.73 8058.67 5,631,310,000 \
1 2018-04-15 7999.33 8338.42 7999.33 8329.11 5,244,480,000
2 2018-04-14 7874.67 8140.71 7846.00 7986.24 5,191,430,000
Market Cap
0 141,571,000,000
1 135,812,000,000
2 133,682,000,000
我能够绘制不同的列:打开,高,低,关闭
但无法显示数量和市值
df.plot(x='Date', y = 'Volume', kind = 'line')
TypeError: Empty 'DataFrame': no numeric data to plot
也在跑步时
df.plot()
ValueError: view limit minimum -36839.658058149995 is less than 1 and is an invalid Matplotlib date value. This often happens if you pass a non-datetime value to an axis that has datetime units
但我可以肯定df ['Date']是日期时间对象
print(df.dtypes)
Date datetime64[ns]
Open float64
High float64
Low float64
Close float64
Volume object
Market Cap object
dtype: object
要转换object
类型列,可以使用:
df['Market Cap'] = df['Market Cap'].str.replace(',', '').astype(float)
df['Volume'] = df['Volume'].str.replace(',', '').astype(float)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.