简体   繁体   中英

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. (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 )
I firstly tried normal read_csv

df.read_csv('file')

But it turned out that the float64 was parsed as Object , which is not what I want. I read this post , but the solution there is assuming they know the column name and datatype in that column.
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?
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 .

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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