Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pandas as pd
- data = [[1,2,3], [4,5,6], [7,8,9]]
- # create table DataFrame with data
- df = pd.DataFrame(data)
- # sum in rows and put results in new column "sum"
- df['sum'] = df.sum(axis=1)
- # display all
- print(df)
- '''
- 0 1 2 sum
- 0 1 2 3 6
- 1 4 5 6 15
- 2 7 8 9 24
- '''
- data = [[1,2,3], [4,5,6], [7,8,9]]
- for row in data:
- print(row, sum(row))
- '''
- [1, 2, 3] 6
- [4, 5, 6] 15
- [7, 8, 9] 24
- '''
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement