Skip to content

Instantly share code, notes, and snippets.

@kastnerp
Last active May 21, 2021 03:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kastnerp/3929010675f0dec5105a8e881e053732 to your computer and use it in GitHub Desktop.
Save kastnerp/3929010675f0dec5105a8e881e053732 to your computer and use it in GitHub Desktop.
Lambda function with pandas that takes two input which themselves are columns in the DataFrame
df = pd.DataFrame([[4, 9]] * 3, columns=['A', 'B'])
def do_stuff(x,y):
return x*y
df['new']= df.apply(lambda x: do_stuff(x['A'],x['B'] ), axis= 1)
print(df)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment