0

I am trying to convert all rows in one column from a scientific notation to a float. I am trying this solution below but getting a syntax error. Does anyone have a better way of doing it?

future = model.make_future_dataframe(periods=15,freq='M')
forecast = model.predict(future)
forecast.tail(15)

forecast['yhat'] = df.apply({:.7f}.format(forecast['yhat']), axis = 1)
Samir112
  • 125
  • 1
  • 12
  • df['col1'].astype('float')? – INGl0R1AM0R1 Oct 04 '22 at 13:01
  • Does this answer your question? [convert scientific notation to decimal pandas python](https://stackoverflow.com/questions/36810328/convert-scientific-notation-to-decimal-pandas-python) – Naveed Oct 04 '22 at 13:01
  • It didnt work, I think the data in the column is being stored as a float which is correct but when I display it, it displays as scientific notation. How can I force that its displays as a float? – Samir112 Oct 04 '22 at 13:06

1 Answers1

0

to force a display as decimal using set_option

pd.set_option('display.float_format', '{:.7f}'.format)
df = pd.DataFrame({
    'Name': ['a', 'b', 'c'],
    'Value': np.random.rand(3)**22
})
df


    Name    Value
0   a   3.803715e-02
1   b   3.056442e-03
2   c   4.176117e-10

pd.set_option('display.float_format', '{:.7f}'.format)

    Name    Value
0   a   0.0380371
1   b   0.0030564
2   c   0.0000000


# reset the format option
pd.reset_option('display.float_format')
Naveed
  • 11,495
  • 2
  • 14
  • 21