3

There is a number of questions about suppressing scientific notation in Pandas in general

However, none of them seems to apply to the to_markdown function. For example:

import pandas as pd

df = pd.DataFrame({'val': 3e10}, index=[0])  # print(df) gives 3.000000e+10
pd.set_option('float_format', '{:f}'.format) # print(df) gives 30000000000.000000

However, df.to_markdown() still yields

|    |   val |
|---:|------:|
|  0 | 3e+10 |

How can I disable the scientific notation in to_markdown()?

Dahn
  • 1,397
  • 1
  • 10
  • 29

2 Answers2

7

I figured out the answer during writing the question.

df.to_markdown() uses tabulate under the hood. We can thus use the floatfmt parameter mentioned in the tabulate readme to disable the formatting:

print(df.to_markdown(floatfmt=''))

yields

|    |           val |
|---:|--------------:|
|  0 | 30000000000.0 |

as @oneextrafact notes in their answer, you can use floatfmt='.0f' to control the number of decimal places shown.

Dahn
  • 1,397
  • 1
  • 10
  • 29
3

To build on @dahn's answer, if you don't want the decimal point use this format string:

print(df.to_markdown(floatfmt='.0f'))
oneextrafact
  • 159
  • 1
  • 9