【问题标题】:Numerical Column Not displaying numerical correctly in DF数字列在 DF 中未正确显示数字
【发布时间】:2019-09-17 00:25:01
【问题描述】:

我有一个如下的df (例如3行)

ID | Dollar_Value
C       45.32
E       5.21
V       121.32

当我在我的笔记本中查看 df 时,例如 df: 它将 Dollar_value 显示为

ID | Dollar_Value
C       8.493000e+01
E       2.720000e+01
V       1.720000e+01

而不是常规格式,但是当我尝试过滤特定 ID 的 df 时,它会显示应为的值(82.23 或 2.45)

df[df['ID'] == 'E']

 ID | Dollar_Value
 E       45.32

有什么我必须明智地进行格式化的吗?那么 df 本身可以按预期显示值列吗?

谢谢!

【问题讨论】:

    标签: python python-3.x pandas data-science


    【解决方案1】:

    您可以尝试在 print 之前运行此代码,因为您的列可能有大数字或非常小的数字。(请与 df.describe() 核对)

    pd.set_option('display.float_format', lambda x: '%.3f' % x)
    

    【讨论】:

    • 谢谢,lambda 中的代码是做什么的? ('%.3f' % x)
    • @Chris90 设置回位
    猜你喜欢
    • 2012-08-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-01-29
    • 2014-05-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多