【问题标题】:Suppress scientific notation in to_markdown() in pandas在 pandas 的 to_markdown() 中抑制科学记数法
【发布时间】:2021-06-17 04:08:31
【问题描述】:

一般来说,Pandas 中存在许多关于抑制科学记数法的问题

但是,它们似乎都不适用于to_markdown 函数。例如:

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

但是,df.to_markdown() 仍然产生

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

如何禁用to_markdown() 中的科学记数法?

【问题讨论】:

    标签: python pandas dataframe


    【解决方案1】:

    要建立在@dahn 的答案上,如果您不想要小数点,请使用以下格式字符串:

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

    【讨论】:

      【解决方案2】:

      我在写问题的过程中想出了答案。

      df.to_markdown() uses tabulate 在引擎盖下。因此,我们可以使用tabulate readme 中提到的floatfmt 参数来禁用格式化:

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

      产量

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

      【讨论】:

        猜你喜欢
        • 2020-05-31
        • 1970-01-01
        • 2013-07-18
        • 1970-01-01
        • 2017-03-13
        • 1970-01-01
        • 2014-02-03
        相关资源
        最近更新 更多