基于其他列熊猫汇总和保存列的值

时间:2019-04-19 10:45:51

标签: python pandas dataframe

df1 =

(c <= 1).astype(int)

我想做A B 61880 7 62646 8 62651 9 62656 10 62783 11 61880 3 62646 2 ,但要根据“ A”的值将“ B”的结果另存为新列“ B_updated”

data.groupby('A')['B'].sum()之后,我的输出是:

data.groupby('A')['B'].sum()

这很好,但是我无法执行进一步的操作。因此,我要保存“ B”和“ A”。因为我的下一个操作将是Math operations of column based on same values of other column pandas

1 个答案:

答案 0 :(得分:0)

尝试一下:

x_df = df.groupby('A').size().reset_index(name='B_updated')
print(x_df)