Hello. There is a date frame type

| one | two | three | four |


First | sec | three | 123 |

I do the fifth column of code

input['five'] = input['four'].sum() 

How to change the code so that there would be a sum on each line with three columns one, two, three?

1 answer 1

Example:

 In [8]: df = pd.DataFrame(np.random.randint(10, size=(5, 4)), columns='one two three four'.split()) In [9]: df Out[9]: one two three four 0 3 1 2 5 1 2 5 2 1 2 5 1 3 9 3 5 6 7 2 4 9 6 0 2 In [10]: df['five'] = df[['one','two','three']].sum(axis=1) In [11]: df Out[11]: one two three four five 0 3 1 2 5 6 1 2 5 2 1 9 2 5 1 3 9 9 3 5 6 7 2 18 4 9 6 0 2 15