Skip to content

Instantly share code, notes, and snippets.

@justinhchae
Last active January 3, 2021 20:24
Show Gist options
  • Save justinhchae/c3945418af0ae9fc6d79fca8deabc10b to your computer and use it in GitHub Desktop.
Save justinhchae/c3945418af0ae9fc6d79fca8deabc10b to your computer and use it in GitHub Desktop.
Lambda function with two conditional statements
# 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