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()
?
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 |
To build on @dahn's answer, if you don't want the decimal point use this format string:
print(df.to_markdown(floatfmt='.0f'))
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.