如何对熊猫的价值和总和进行分组

时间:2018-10-25 16:46:33

标签: python-2.7 pandas

考虑此熊猫数据框:

import pandas as pd
df = pd.DataFrame(columns=['city','pop'])
df['city'] = ['faa','foo','faa','faa','foo']
df['pop'] = [10,20,15,30,60]

  city  pop
0  faa   10
1  foo   20
2  faa   15
3  faa   30
4  foo   60

如何总结每个城市的流行音乐?我想获得

   city  pop
0   faa   55
1   foo   80

0 个答案:

没有答案