Make new column in Panda dataframe by adding values from other columns

前端 未结 10 995
情歌与酒
情歌与酒 2020-12-13 01:59

I have a dataframe with values like

A B
1 4
2 6
3 9

I need to add a new column by adding values from column A and B, like

         


        
10条回答
  •  南方客
    南方客 (楼主)
    2020-12-13 02:10

    You could use sum function to achieve that as @EdChum mentioned in the comment:

    df['C'] =  df[['A', 'B']].sum(axis=1)
    
    In [245]: df
    Out[245]: 
       A  B   C
    0  1  4   5
    1  2  6   8
    2  3  9  12
    

提交回复
热议问题