Advertisement
elena1234

vectorize and apply on multiply columns in Python

Apr 19th, 2022 (edited)
738
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.30 KB | None | 0 0
  1. def quality(total_bill, tip):
  2.     if tip/total_bill > 0.25:
  3.         return "Generous"
  4.     else:
  5.         return "Other"
  6.  
  7. df['Quality'] = df[['total_bill', 'tip']].apply(lambda df: quality(df['total_bill'], df['tip']), axis = 1)
  8.  
  9. # or
  10. df['Quality'] = np.vectorize(quality)(df['total_bill'], df['tip'])
  11.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement