Skip to content

Instantly share code, notes, and snippets.

@justinhchae
Created December 30, 2020 22:14
Show Gist options
  • Save justinhchae/1402ab49e90d1f5ac0e36af4a6bb0bc2 to your computer and use it in GitHub Desktop.
Save justinhchae/1402ab49e90d1f5ac0e36af4a6bb0bc2 to your computer and use it in GitHub Desktop.
A simple, do nothing lambdas function on a DataFrame
# copy col2 value into a new column
col_new = str(col1 + '_new')
df[col_new] = df.apply(lambda x: x[col2] , axis=1)
print(df[[col1, col_new, col2]].head(2))
# output
"""
event_date event_date_new received_date
2011-01-05 2011-01-31 2011-01-31
2011-01-05 2011-01-31 2011-01-31
"""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment