2021年4月8日星期四

Why pd.read_csv('file.csv') add .999999 at the end of some values?

I have a csv file with 4 rows and 1 column. When I open it with Sublime it looks like this:

2.291433301000000000e+09  3.601532401000000000e+09  3.061400502000000000e+09  3.195901470100000000e+10  

When I read it using:

df = pd.read_csv('file.csv', names=['Column 1'])  

The value at the last row in python is 31959014700.999996

How can I solve the issue? I tried adding data type when reading the file:

df = pd.read_csv('file.csv', names=['Column 1'], dtype=np.int64)  

But didn't work. I also tried:

df = pd.read_csv('file.csv', names=['Column 1'])  df = df(pd.to_numeric, errors='coerce')  

But it says it cannot convert to int!

Thanks for your help.

https://stackoverflow.com/questions/67014522/why-pd-read-csvfile-csv-add-999999-at-the-end-of-some-values April 09, 2021 at 11:04AM

没有评论:

发表评论