我想对我的银行数据有更多的了解。我想查看每个类别的总金额,但我似乎无法对数据集中的金额进行浮动。你知道吗
我已经将数据(csv文件)上传到一个数据帧(bank)中,看起来像这样:
date amount category
2018-09-01 -58,00 dinner
2018-09-02 -60,00 grocery
2018-09-02 -115,00 clothing
我试过使用.replace和.astype(float),两者都不起作用
#I've tried this formula, but it doesn't work (the x-values even get shuffled??):
#replace ',' with '.' in amount:
def komma(x):
for x in bank['amount']:
x = list(set(x))
for a in x:
if a == ',':
a.replace(",",".")
return "".join(x)
komma(x)
bank.head()
#my result with .replace(',','.') is no changes in the dataframe
#my result with .astype(float) was
#ValueError: could not convert string to float: '-58,00'
你可以试试这个:
但是,将“,”转换为“.”之后再转换为float可能会导致数据精度损失。你知道吗
试试这个:
(不需要任何for循环)
相关问题 更多 >
编程相关推荐