我有一个数据框,其中有许多列,但我只对三列感兴趣。它们是name
、year
和goals_scored
。这些列都不是唯一的,例如我有以下行:
Name Year Goals_scored
John Smith 2014 3
John Smith 2014 2
John Smith 2014 0
John Smith 2015 1
John Smith 2015 1
John Smith 2015 2
John Smith 2015 1
John Smith 2015 0
John Smith 2016 1
John Smith 2016 0
我尝试创建一个新的数据框,其中包含4列。一列是名字,然后是2014年、2015年和2016年的每一年各一列。最后三列是该年份进球数的总和。所以使用上面的数据看起来像这样:
Name 2014 2015 2016
John Smith 5 5 1
为了让情况更糟糕,他们只想要包括那些在三年内都有相关内容的名称。请问有人能指点我吗?