Last active
January 3, 2021 20:24
-
-
Save justinhchae/c3945418af0ae9fc6d79fca8deabc10b to your computer and use it in GitHub Desktop.
Lambda function with two conditional statements
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
# lambda with two conditional statements | |
df[col_new] = df.apply(lambda x: x[col1].replace(year=x[col2].year) if x[col1].year > curr_year | |
else x[col1].replace(year=x[col2].year) if x[col1].year < past_year | |
else x[col1] | |
, axis=1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment