Skip to content

Instantly share code, notes, and snippets.

@maptastik
Last active October 9, 2019 15:06
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save maptastik/4d43b67078040c7a45b767540c5f7c43 to your computer and use it in GitHub Desktop.
import pandas as pd
df = pd.DataFrame({'a': [1,2,3], 'b': [2,3,4], 'c':['dd','ee','ff'], 'd':[5,9,1]})
df['e'] = df[['a', 'b', 'd']].sum(axis = 1)
#########################
## RESULT ##
#########################
# a b c d e # COLUMNS
# 0 1 2 dd 5 8 # ROW
# 1 2 3 ee 9 14 # ROW
# 2 3 4 ff 1 8 # ROW
#########################
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment