【问题标题】:how to get column total without resetting indexes in panda如何在不重置熊猫索引的情况下获取列总数
【发布时间】:2020-06-04 15:13:16
【问题描述】:

我想显示它的方式是这样的

                                   ComoQty
DocDate ImportType ForeignType
April   Export     Costal        901637.68
                   Foreign      3258010.20
        Import     Costal        271716.22
                   Foreign      6037122.41
        NET                     <total of export-import>
TOTAL                           <total of the above values of export and import>

这在 pandas 中是否有可能,或者是否有任何不同的方法可以以任何不同的方式实现类似的目标?

【问题讨论】:

    标签: python python-3.x pandas dataframe pandas-groupby


    【解决方案1】:

    为了过滤导出/导入并计算总和,假设数据帧被称为df:

    difference = df[df.ImportType=='Export'].ComoQty.sum()\
                -df[df.ImportType=='Import'].ComoQty.sum()
    

    因此,总数为+。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-02-04
      • 2018-12-26
      • 1970-01-01
      • 2022-11-08
      • 1970-01-01
      • 2021-09-18
      • 2018-07-23
      • 2023-03-26
      相关资源
      最近更新 更多