简体   繁体   English

如何使用 Pandas 处理浮点数中的小数点分隔符?

[英]how to handle decimal separator in float using Pandas?

So basically I have a csv file which consists of two columns in which the data are Cinema name and prices respectively.所以基本上我有一个 csv 文件,它由两列组成,其中数据分别是电影院名称和价格。 (data in Cinema name are all string whereas prices are float64 but may have example like 12,000.0 OR 3,025.54 where I want it to be 12000.0 or 3025.54 ) (电影名称中的数据都是字符串,而价格是 float64,但可能有像12,000.03,025.54这样的例子,我希望它是12000.03025.54
I firstly tried normal read_csv我首先尝试了正常的 read_csv

df.read_csv('file')

But it turned out that the float64 was parsed as Object , which is not what I want.但事实证明float64被解析为Object ,这不是我想要的。 I read this post , but the solution there is assuming they know the column name and datatype in that column.我读了这篇post ,但那里的解决方案假设他们知道该列中的列名和数据类型。
Assuming I don't know what the column name will be, how would I efficiently handle comma separator in float and make it into float instead of object?假设我不知道列名是什么,我将如何有效地处理浮点数中的逗号分隔符并将其变为浮点数而不是 object?
Note I only want to handle ',' only for float Data not String data.请注意,我只想处理“,”,仅用于浮点数据而不是字符串数据。
Thanks for your helps..谢谢你的帮助。。

Pandas read_csv function has a thousands argument, which you can specify to be , instead of the default . Pandas read_csv function 有一个thousands位参数,您可以将其指定为,而不是默认的.

df.read_csv('file', thousands=',')

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

相关问题 python - 如何在Python Pandas中使用逗号作为小数点分隔符的浮点格式? - How to have float format with comma as a decimal separator in Python Pandas? 使用以逗号作为小数点分隔符的熊猫样式 - Use pandas style using comma as decimal separator 如何用逗号格式化浮点数作为 f 字符串中的小数点分隔符? - How to format a float with a comma as decimal separator in an f-string? python十进制奇怪句柄以及如何获得最接近的十进制浮点数? - python decimal strange handle and how to get the closest one decimal float? 如何使用带有逗号小数分隔符的 pandas.to_clipboard - How to use pandas.to_clipboard with comma decimal separator 如何将我的浮点数更改为两位十进制数字,并使用逗号作为python中的小数点分隔符? - How do I change my float into a two decimal number with a comma as a decimal point separator in python? 在小数点分隔符之前也在python中格式化浮点数 - Formatting float in python also before the decimal separator 熊猫:关于如何处理缺少的小数的建议 - Pandas: Recommendation on how to handle missing decimal 使用 float64 的熊猫最大小数位数 - pandas maximum number of decimal places using float64 如何使字符串格式以固定的精度和语言环境类型的小数点分隔符浮动? - How to make string format float with fixed precision and locale type decimal separator?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM