I have a pandas dataframe that looks like this:
JavaScript
x
12
12
1
data
2
0 [26.113017616106, 106.948066803935, 215.488217
3
1 [26.369709448639, 106.961107298101, 215.558911
4
2 [26.261267444521, 106.991763898421, 215.384122
5
3 [26.285746968657, 106.912377030428, 215.287348
6
4 [26.155342026996, 106.825440402654, 215.114619
7
5 [26.159917638984, 106.819720887669, 215.117593
8
6 [26.023564401739, 106.843056508808, 215.129947
9
7 [26.1155342027, 106.828185769847, 215.15991763
10
8 [26.028826355525, 106.841912605811, 215.146190
11
9 [26.015099519561, 106.824296499657, 215.130404
12
I am trying to extract the 1st element from the Series of lists using this code:
JavaScript
1
2
1
[x[1] for x in df.data]
2
and I get this result:
JavaScript
1
11
11
1
0 106.948067
2
1 106.961107
3
2 106.991764
4
3 106.912377
5
4 106.825440
6
5 106.819721
7
6 106.843057
8
7 106.828186
9
8 106.841913
10
9 106.824296
11
Why do I lose precision and what can I do to keep it?
Advertisement
Answer
By default, pandas displays floating-point values with 6 digits of precision.
You can control the precision with pandas’ set_option e.g.
JavaScript
1
2
1
pd.set_option('precision', 12)
2