1

I want to import a text file (forward_extensive.par) that has 12 significant figures but when I use pd.read_csv it only imports 6.

I have tried searching for this question online but I can't fins any reference to changing the precision in pd.

par_path = os.path.join(path, forward_extensive.par)                                 # define path to parameter realisation file
par = pd.read_csv(par_path, sep=r"\s*",index_col=False, header=None, skiprows=1)  

I want values to 12 decimal places instead of 6.

Any advice would be much appreciated.

Mohit Motwani
  • 4,662
  • 3
  • 17
  • 45
Emma
  • 443
  • 2
  • 5
  • 13
  • 1
    Can you check parameter [`float_precision='round_trip'`](https://stackoverflow.com/a/36909497) ? – jezrael Jun 17 '19 at 06:09
  • I tried pd.option_context('display.precision',12) but nothing changed. I am using python 2.7 – Emma Jun 17 '19 at 06:18

2 Answers2

0

You data is imported with all decimals till float point. To print them use options.display:

import pandas as pd

data = pd.read_csv('data.csv')
pd.options.display.float_format = '{:,.16f}'.format
print(data.head())
Zaraki Kenpachi
  • 5,510
  • 2
  • 15
  • 38
0

Take a look at https://pandas.pydata.org/pandas-docs/stable/user_guide/options.html

This page mentions display.precision option, but for some reason code samples use only precision name, e.g.:

pd.set_option('precision', 7)

So try pd.set_option('precision', 12).

Another suggestion: Upgrade your Python installation, e.g. to 3.7 version.

Valdi_Bo
  • 30,023
  • 4
  • 23
  • 41