how to get rid of pandas converting large numbers in excel sheet to exponential? how to get rid of pandas converting large numbers in excel sheet to exponential? python python

how to get rid of pandas converting large numbers in excel sheet to exponential?


The way scientific notation is applied is controled via pandas' display options:

pd.set_option('display.float_format', '{:.2f}'.format)df = pd.DataFrame({'Traded Value':[67867869890077.96,78973434444543.44],                   'Deals':[789797, 789878]})print(df)       Traded Value   Deals0 67867869890077.96  7897971 78973434444543.44  789878

If this is simply for presentational purposes, you may convert yourdata to strings while formatting them on a column-by-column basis:

df = pd.DataFrame({'Traded Value':[67867869890077.96,78973434444543.44],                   'Deals':[789797, 789878]})df    Deals   Traded Value0   789797  6.786787e+131   789878  7.897343e+13df['Deals'] = df['Deals'].apply(lambda x: '{:d}'.format(x))df['Traded Value'] = df['Traded Value'].apply(lambda x: '{:.2f}'.format(x))df         Deals       Traded Value0   789797  67867869890077.961   789878  78973434444543.44

An alternative more straightforward method would to put the following line at the top of your code that would format floats only:

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