在此数据框中,我想按“位置”进行分组并获得“分数”的总和,但我不希望“纬度”、“经度”和“年份”在此过程中受到影响;
sample = pd.DataFrame({'Location':['A','B','C','A','B','C'],
'Year':[2001,2002,2003,2001,2002,2003],
'Lat':[24,32,14,24,32,14],
'Long':[81,85,79,81,85,79],
'Score':[123,234,10,25,46,11]})
grouped = sample.groupby(['Location']).sum().reset_index()
grouped
给我这个;
Location Lat Long Score Year
0 A 48 162 148 4002
1 B 64 170 280 4004
2 C 28 158 21 4006
但我正在寻找这个结果;
Location Lat Long Score Year
0 A 24 81 148 2001
1 B 32 85 280 2002
2 C 12 79 21 2003