简体   繁体   English

熊猫read_csv-千位分隔符工作不一致

[英]Pandas read_csv - thousands separator working inconsistent

I am trying to read a csv file with commas as thousands separators into a pandas dataframe. 我正在尝试使用逗号将csv文件读取为pandas数据帧中的数千个分隔符。 The one time I am running the code it runs fine, while the other time it does not parse one of the columns correctly. 一次,我运行代码可以正常运行,而另一次,它无法正确解析其中一列。 Please find an example of my code below: 请在下面找到我的代码示例:

df_uv = pd.read_csv(file, sep=',', parse_dates=[0, 1, 2], usecols=columns_to_use,
                    thousands=',').fillna(0)

Please find below an example of the way the data is formatted in the csv file 请在下面找到有关在csv文件中格式化数据的方式的示例

03 Jan 2017,29 Dec 2016,30 Dec 2016,XXX,XXXX,XXXX,,,,,"14,214.08","-9,095.36","23,309.44","7,530.48","-15,962.64","23,493.12",

Any tips on how to tackle this issue? 有关如何解决此问题的任何提示?

I decided to change my code into the following: 我决定将代码更改为以下内容:

df_uv = pd.read_csv(file, sep=',', parse_dates=[0, 1, 2], thousands=',').fillna(0)
df_uv = df_uv[columns_to_use]

Which is working completely fine. 这完全正常。

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

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