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

前端 未结 10 994
情歌与酒
情歌与酒 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:09

    You could do:

    df['C'] = df.sum(axis=1)
    

    If you only want to do numerical values:

    df['C'] = df.sum(axis=1, numeric_only=True)
    

提交回复
热议问题