whytheq whytheq - 1 year ago 57
Python Question

Why are these tuple values seemingly losing their precision

I have the following:

import pandas as pd
def TupFirst(x):
return x[0]
def TupSecond(x):
return x[1]

df = pd.DataFrame(data = {'colX': [(51.2990505474, 0.802680507953),(51.7491674401, -4.96357522689)]})
df['colY'] = df['colX'].apply(TupFirst)
df['colZ'] = df['colX'].apply(TupSecond)

Which returns the following dataframe:

colX colY colZ
0 (51.2990505474, 0.802680507953) 51.299051 0.802681
1 (51.7491674401, -4.96357522689) 51.749167 -4.963575

Why are the values in colY and colZ being rounded?

Answer Source

What you're seeing is the result of a display configuration in pandas. The full precision is still there. Check it with:

print(df.loc[1, 'colz'])

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download