Skip to content

Instantly share code, notes, and snippets.

@anxiousmodernman
Created July 30, 2014 22:06
Show Gist options
  • Save anxiousmodernman/733384a49172c280ccaf to your computer and use it in GitHub Desktop.
Save anxiousmodernman/733384a49172c280ccaf to your computer and use it in GitHub Desktop.
def row_processor(row):
if row['lookupColumn'] == 1:
# add all 3 columns
value = row['colA'] + row['colB'] + row['colC']
return value
elif row['lookupColumn'] == 2:
# add just 2 specific columns referenced by name
value = row['colA'] + row['colB']
return value
else:
value = row['colA']
return value
# now use it in your apply. You don't have to use lambdas in apply i think...
df.apply(row_processor(row), axis=1) # i think axis 1 is right. I forget which way is up! :)
@ahelium
Copy link

ahelium commented Jul 31, 2014

Right. I also wrote something like this and will probably end up using it. :(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment