aseb
aseb

Reputation: 27

Python Rounds off values while importing/exporting from/to a scv file

While importing or exporting to a CSV file, I see that python rounds off value but only for certain rows/columns whereas the other data is kept intact. Not sure why this is happening for certain rows/columns even though the length of the numbers are same (all are 12 digit numbers).

For example:

| Python Version | Excel Version |

|126000000000|125568000000|
|113000000000|112661000000|
|258000000000|258267783000| . . . Whereas the other 12 or more digit numbers are not rounded. Any help would be much appreciated. Thanks!

Upvotes: 0

Views: 188

Answers (1)

Balaganesh
Balaganesh

Reputation: 23

Change few arguments in pandas.read_csv() to try and force correct data types. I would suggest changing dtype to 'float64' and float_precision='round_trip'. Check for other arguments if applicable here.

https://pandas.pydata.org/docs/reference/api/pandas.read_csv.html#pandas-read-csv

It could also be a visual thing, check you pd.set_option values as well.

Upvotes: 0

Related Questions