2

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

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

1 Answer 1

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)
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.