Python 如何在不重置panda中的索引的情况下获取列总数
我想展示的方式是这样的Python 如何在不重置panda中的索引的情况下获取列总数,python,python-3.x,pandas,dataframe,pandas-groupby,Python,Python 3.x,Pandas,Dataframe,Pandas Groupby,我想展示的方式是这样的 ComoQty DocDate ImportType ForeignType April Export Costal 901637.68 Foreign 3258010.20 Import Costal 271716.22 Foreign 603
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中,这是否可能以任何方式实现,或者是否有任何不同的方法以任何不同的方式实现类似的目标?要过滤导出/导入并计算总和,假设数据帧称为df: 相应地,总数为+
difference = df[df.ImportType=='Export'].ComoQty.sum()\
-df[df.ImportType=='Import'].ComoQty.sum()