【问题标题】:Why python returns scientific notation when calculate in the dataframe?为什么 python 在数据框中计算时返回科学计数法?
【发布时间】:2018-10-19 15:55:40
【问题描述】:

当我使用 Python 在数据框中进行计算时,它会返回科学记数法结果...是否有方法在没有科学记数法的情况下生成结果(只返回浮点数)?那些突出显示的数字应该是 0。

感谢您的帮助。

【问题讨论】:

  • 您要对它们进行四舍五入吗?或者只是获得完整的浮动?
  • 我需要完整的浮动。但是那些突出显示的数字应该是 0。我不知道为什么 Python 会返回这些格式......

标签: python pandas math scientific-notation


【解决方案1】:

选项1:您可以使用一个选项:display.precision:pd.set_option('precision', 5)

Options and Settings

选项2:可以使用浮点格式:

pd.options.display.float_format = '${:,.5f}'.format

选项3:你可以使用圆形:

DataFrame.round(decimals=0, *args, **kwargs) to can round close to the nearest number:

df.round(5) # for whole dataframe

pandas.DataFrame.round

【讨论】:

  • 是的,在所有情况下都将小数点保留为 5,您可以更改您的要求。大多数情况下,我使用 display.float_format 并且一直在工作。
  • 知道了。谢谢!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2010-09-16
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多