简体   繁体   English

使用 Pandas 时如何从 CSV 文件列中删除 1000 个分隔符?

[英]How to delete 1000 separator from CSV file columns when using Pandas?

I'm handling a CSV file with several columns and rows.我正在处理一个包含多列和多行的 CSV 文件。 The values in my CSV file are integers with 1000 separator like 99 999 and 87 222. I'm trying to calculate mean values but I'm getting an error Exception has occurred: DataError No numeric types to aggregate and I'm pretty sure it is because of the 1000 separators in my values.我的 CSV 文件中的值是具有 1000 个分隔符的整数,例如 99 999 和 87 222。我正在尝试计算平均值,但出现错误Exception has occurred: DataError No numeric types to aggregate我很确定是因为我的值中有 1000 个分隔符。

data = pd.read_csv('newdata.csv', sep = ";", skiprows=[0], skipinitialspace=True)

That doesn't fix my problem.那不能解决我的问题。 I have also tried data["First title"] = data["First title"].str.strip() for every column but that didn't work either.我也为每一列尝试了data["First title"] = data["First title"].str.strip() ,但这也不起作用。

Better ideas?更好的想法? Thanks!谢谢!

The pandas read_csv method has a "thousands" optional parameter, which you could use to indicate what this thousands separator is. pandas read_csv 方法有一个“千”可选参数,您可以使用它来指示这个千位分隔符是什么。

Hence, you can use something like因此,您可以使用类似的东西

df = pd.read_csv('newdata.csv', sep = ";", thousands = ' ')

to handle your data input.处理您的数据输入。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM