How to change numeric data format for html output

Viewed 3015

I have code to produce a pandas dataframe and send email in html format.
The problem I have is hard to change the scientific format of numeric numbers to general in style

I already tried to set float format, but it did not work.

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

output:

Col A        Col B
1.00E+06    2.28E+06
3.00E+07    -2.54E+07

expected out:

Col A        Col B
1000420      2281190
30030200    -25383100
2 Answers

I couldn't reproduce your problem with the example you stated. It might be something that changes the dataframe format within your code. But I believe this code can help you:

import pandas as pd
df = pd.DataFrame({"Col A":[1000420, 30030200],"Col B": [2281190, -25383100]})
for col in df:
    df[col] = df[col].apply(lambda x: "%.f" % x)

With this you get as output:

>>> df
      Col A      Col B
0   1000420    2281190
1  30030200  -25383100
Related