I want to read a csv but it culls the number of decimals:
fname = './sol/Pret-SB_A00DLR0_202205240635.pos'
skiprow = 0
with open(fname) as search:
for i, line in enumerate(search):
if "% GPST" in line:
skiprow = i
break
df = pd.read_csv(fname, skiprows=skiprow, delim_whitespace=True, parse_dates=[[0, 1]])
df.head(2)
gives (first 2 rows, first five columns):
the original data (here) has 8 decimal places in the 3rd and 4th columns. I need those.
2211 196568.000 -25.732036008 28.282629130 1387.8994
2211 196569.000 -25.732032386 28.282633712 1389.4025
How do I read a csv and retain the precision of the original data?
CodePudding user response:
How do I read a csv and retain the precision of the original data?
You do have it, pandas
simply limit number of digits for presentation purposes, consider following example
import pandas as pd
df = pd.DataFrame({'x':[28.282633712]})
print(df)
print(df.x[0])
print(df.x[0] == 28.282633712)
gives output
x
0 28.282634
28.282633712
True
CodePudding user response:
You can set the number of displayed digits to 8 like this:
pd.options.display.float_format = "{:,.8f}".format