[英]Pandas DataFrame - summing rows by multiple column values
I am working on a Pandas dataframe in Python, i would like to do following rearrangement of the dataset :我正在 Python 中处理 Pandas 数据框,我想对数据集进行以下重新排列:
I tried using for loops, but I wonder if there is any simpler solution using Pandas - i couldn't find anything more elegant.我尝试使用 for 循环,但我想知道是否有使用 Pandas 的更简单的解决方案 - 我找不到更优雅的东西。
用 :
df.groupby(['Year','Sex'],as_index=False).sum()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.