我使用的代码:
car_sales["Price"]=car_sales["Price"].int.replace('[\$\,\.]', '').astype(int)
将我的dataframe
列从对象转换为int
,这样我就可以绘制它了。这样做删除了所有符号,并将它们转换为包括小数点在内的空字符串,现在我的价格从22,000.00美元变成了2200,000美元。
如何将小数放回原处,并在可能的情况下将列保持为int
?
我试过小数= pd.Series([2],index=['Price'])car_sales.round(小数)
什么都没改变,其他小的调整也没有成功。
1条答案
按热度按时间vuktfyat1#
你有没有试过用这样的东西:
通过在replace中不包含
.
符号,您不需要重新排列整个系列来考虑删除的小数。