简体   繁体   English

在 pandas 中的 to_markdown() 中禁止科学记数法

[英]Suppress scientific notation in to_markdown() in pandas

There is a number of questions about suppressing scientific notation in Pandas in general一般来说,在 Pandas 中有许多关于抑制科学记数法的问题

However, none of them seems to apply to the to_markdown function.但是,它们似乎都不适用于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但是, df.to_markdown()仍然产生

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

How can I disable the scientific notation in to_markdown() ?如何禁用to_markdown()中的科学记数法?

I figured out the answer during writing the question.我在写这个问题的时候想出了答案。

df.to_markdown() uses tabulate under the hood. df.to_markdown()在后台使用制表 We can thus use the floatfmt parameter mentioned in the tabulate readme to disable the formatting:因此,我们可以使用制表自述文件中提到的floatfmt参数来禁用格式化:

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:要以@dahn 的答案为基础,如果您不想要小数点,请使用以下格式字符串:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM