简体   繁体   English

大熊猫重复索引操作

[英]Operations on repeated index in pandas

    P   d
A   3   2
A   3   3
A   1   1
A   1   1
B   6   9
B   3   9
B   1   9
C   5   1
C   2   1

I have scv file that is full of similar data indixed with repeated a , b , c ....... etc , has columns labeled price , data and some other labels, how to calculate the sum of all the numbers in the price column that are indexed with every single index alone , and repeat the process for other all indexes , without knowing all the indexes ? 我有一个scv文件,里面充满了重复的a,b,c .......等类似数据,其中的列标记为price,data和一些其他标签,如何计算价格中所有数字的总和仅对每个索引都建立索引的列,并在不知道所有索引的情况下对其他所有索引重复该过程?
For example : The price of A =8 The price of C = 7 例如:A的价格= 8 C的价格= 7

按索引分组

df.groupby(level=0).P.sum()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM