简体   繁体   English

根据不同列中的其他2个值汇总一列的值

[英]sum up values of a column depending on 2 other values ​from different columns

I'm using jupyter notebook to visualize some data with python. 我正在使用jupyter笔记本用python可视化一些数据。 I got a dataframe with following columns: matchid, player, visionscore, win 我有一个包含以下几列的数据框:matchid,player,visionscore,win

given table 给定表

Now i want to sum up the visionscore. 现在,我想总结一下愿景得分。 For every matchid there are 10 entries given, which go from player 1 to 10 (player 1-5 = team 1, 6-10 = team 2) and each player has it's own visionscore. 对于每个比赛ID,都有10个条目,从玩家1到10(玩家1-5 =团队1,6-10 =团队2),每个玩家都有自己的视野。 Now i want to have something like this: 现在我想要这样的东西:

expected result 预期结果

Obviously im new to data analytics. 显然,我是数据分析的新手。 I allready have a table where the visionscore/matchid is summed up, but unfortunately there is no seperation between the teams. 我已经有一张表格汇总了visionscore / matchid,但不幸的是,团队之间没有分隔。 So it's the whole visionscore for the game. 因此,这就是游戏的整体愿景。

table i allready got 我已经准备好的桌子

I randomly generated data, but I think this should work. 我随机生成数据,但是我认为这应该可行。

df['team'] = [1 if p<=5 else 2 for p in df.player]
df.groupby(['matchid', 'team'])['visionscore', 'win'].sum()

matchid team    visionscore win
10      1       274         3
10      2       124         3
11      1       416         3
11      2       89          0

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

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