I want to read a csv but it culls the number of decimals:
JavaScript
x
10
10
1
fname = './sol/Pret-SB_A00DLR0_202205240635.pos'
2
skiprow = 0
3
with open(fname) as search:
4
for i, line in enumerate(search):
5
if "% GPST" in line:
6
skiprow = i
7
break
8
df = pd.read_csv(fname, skiprows=skiprow, delim_whitespace=True, parse_dates=[[0, 1]])
9
df.head(2)
10
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?
Advertisement
Answer
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
JavaScript
1
6
1
import pandas as pd
2
df = pd.DataFrame({'x':[28.282633712]})
3
print(df)
4
print(df.x[0])
5
print(df.x[0] == 28.282633712)
6
gives output
JavaScript
1
5
1
x
2
0 28.282634
3
28.282633712
4
True
5