'Pandas approximating/rounding large numbers from csv

I am reading numbers from a csv file into a pandas dataframe. When the numbers I am reading are approximately >1E12, pandas will approximate the number to 3 significant figures. For example, 9215069800000 will be approximated to 9.22E12 (i.e., stop pandas changing 9215069800000 to 9220000000000).

This may not seem like a significant issue, but these small differences, at times, lead to significant issues.

I have tried float_precision='round_trip' but this only accepts decimal places.

I have also tried pd.set_option('display.float_format', lambda x: '%.5f' % x) but this too does not work.

Any help would be greatly appreciated.



Solution 1:[1]

Just set float_precision=None parameter to none when reading the csv

import pandas as pd

with pd.option_context('display.precision', 10):
    df = pd.read_csv("test.csv", float_precision=None)
    print(df)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1