1

I have a dataframe (df) like the following

enter image description here

I'm trying to convert the values in dataframe to int and float64 types.

df['poiid'] = df['poiid'].astype(int)
df['lng'] = df['lng'].astype('float64')
df['lat'] = df['lat'].astype('float64')

The code above does not work properly for float64, it only takes 6 decimal values after comma for lng and lat attributes. ( Please see the Output below)

Output

enter image description here

My expectation is 10 digits after the comma

my expectation output:

8904  -94.6074986458, 39.0523183095

...
drorhun
  • 500
  • 7
  • 22
  • 1
    Are you sure it's not just a limit in the displayed precision, while the dataframe actually holds what you expect? – couka Jan 26 '21 at 14:02
  • 1
    what you see is just the default string representation with 6 decimal places, the number may have more decimal places – Stef Jan 26 '21 at 14:02
  • 2
    just try `pd.options.display.float_format = '{:.10f}'.format` – Stef Jan 26 '21 at 14:03

1 Answers1

2

What you see is just the default string representation with 6 decimal places. You can set you own display format option with

pd.options.display.float_format = '{:.10f}'.format

to show 10 places. Alternatively you can confirm the number if you look at the result of say df.loc[1,'lng'].

To set the option only temporarily you can use an option context:

with pd.option_context('display.float_format', '{:.10f}'.format):
    print(df)
Stef
  • 28,728
  • 2
  • 24
  • 52