我有一个数据帧:
product = DataFrame({'_product': ['shoes','dress','cap','shoes','purse','t-shirt','t-shirt','dress','t-shirt'],
'city': ['A','A','A','B','A','A','B','C','A'],
'color':['red','black','black','white','black','green','white','yellow','blue'],
'size':['36','S','M','40','-','L','L','M','S'],
'param1':['x0001','x0008','x0006','x0002','x0001','x0009','x0011','x0003','x0001'],
'param2':[23,1,367,689,35,97,100,44,15],
'param3':['f1','t1','u7','f1','r4','f2','f2','t2','f4'],
'counter':[1,1,1,1,1,1,1,1,1]})
table=product[['_product','city','color','size','param1','param2','param3','counter']]
申请
^{pr2}$我得到一个只包含总计行(“All”)的透视表。在
这是一个假设的示例,实际上我导入了一个包含10万行和20列的表。在
!!对我来说,在产品级别上有小计是绝对必要的。在
是否有任何有效的方法可以将包含小计的行插入此表中,就像具有字段设置的Excel数据透视表gt;Layout&Print>;“以表格形式显示项目标签”所允许的那样?在
我不熟悉Excel中的那个操作,但这里有一个按产品计算小计的一行程序。在
可能是您想要
np.size
在哪里使用np.count
,这取决于'counter'列的含义。在相关问题 更多 >
编程相关推荐