Sum of several columns from a pandas dataframe

后端 未结 2 682
甜味超标
甜味超标 2021-02-15 15:01

So say I have the following table:

In [2]: df = pd.DataFrame({\'a\': [1,2,3], \'b\':[2,4,6], \'c\':[1,1,1]})

In [3]: df
Out[3]: 
   a  b  c
0  1  2  1
1  2  4           


        
2条回答
  •  南旧
    南旧 (楼主)
    2021-02-15 15:42

    Maybe you are looking something like this:

    df["result"] = df.apply(lambda row: row['a' : 'c'].sum(),axis=1)
    

提交回复
热议问题