Created
July 30, 2014 22:06
-
-
Save anxiousmodernman/733384a49172c280ccaf to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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! :) |
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
might need extra handling of all-blank input here. If you go with this approach you could drop a debugger breakpoint on line 2 and inspect what's going on when the code runs.