如何向数据帧添加新行以满足列中的条件,以及如何复制其余列

How to add new rows to a dataframe in order to satisfy a condition in a column, and copying the rest of the columns

提问人:Cristina Dominguez Fernandez 提问时间:11/8/2023 更新时间:11/8/2023 访问量:22

问:

我有一个这样的数据帧:

df1 = pd.DataFrame({
        "client":[1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,2,2,3,3],
        "month": [1,2,3,4,5,1,2,3,4,5,6,7,8,9,10,11,12,1,2],
        "año:[2017,2017,2017,2017,2017,2017,2017,2017,2017,2017,2017,2017,2017,2017,2017,2017,2017,2017,2017],
    "total": [25,30,5,40,6,55,25,85,4,9,5,40,6,55,25,85,4,9,10]
})

我想要的是每年 12 个月的每个客户行。对于这个新行,我想用 0 填充列总数,并从同一年份和客户的行中复制信息。

添加

评论


答: 暂无答案