Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
535 views
in Technique[技术] by (71.8m points)

python - Pandas group by index and calculate sum

I have the following dataframe:

Node  Type       
0     InData         2944.516970
      InInterests    3703.208935
1     InData         6207.580040
      InInterests    3505.068411
2     InData         8133.002730
      InInterests    3735.028306
3     InData         9426.704710
      InInterests    2665.989291
4     InData         2604.157800
      InInterests    3103.310729
5     InData         6784.829160
      InInterests    3293.815375
6     InData         6823.617400
      InInterests    4121.833980
7     InData         4072.702770
      InInterests    3033.609368
8     InData         4614.608240
      InInterests    2955.216811
9     InData         6986.500750
      InInterests    2986.820394
Name: KilobytesRaw, dtype: float64

I want to compute the sum of InData and InInterests, but couldn't find this case in the Pandas indexing page, nor on Google. So my I want my dataframe to look like this

Node         
0     mean         2944.516970
1     mean         6207.580040
...
9     mean         8133.002730

Can anybody help please?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Got it done by using df.groupby(level=0).sum()


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...