【问题标题】:How do you display all values when using pivot tables in pandas?在 pandas 中使用数据透视表时如何显示所有值?
【发布时间】:2022-06-24 01:05:52
【问题描述】:
df_agg = pd.pivot_table(df, values= 'total_revenue', index= 'order_year',aggfunc= 'sum')

当我运行上面的代码时,这就是我得到的。我很想获得总收入列的全部数据。

order_year total_revenue
2010 4.95994e+08
2011 5.23411e+08

【问题讨论】:

    标签: python pandas analytics


    【解决方案1】:

    您可以添加 pandas set_option 来更改查看数字的方式。

    代码

    df_agg = pd.pivot_table(df, values= 'total_revenue', index= 'order_year',aggfunc= 'sum')
    #Used 2 as I think you have financial/currency data
    pd.set_option('display.float_format', lambda x: '%.2f' % x) 
    df_agg
    

    输出

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-04-10
      • 1970-01-01
      • 2014-01-08
      • 1970-01-01
      相关资源
      最近更新 更多