Skip to content
Advertisement

Lambda and vectorize in python

I’m learning data analysis while performing vectorized operation with lambda function it run at first but again run it shows error as TypeError: <lambda>() takes 1 positional argument but 2 were given

sample data of tips.csv file

enter image description here

JavaScript

enter image description here

This is the image that I run first which doesn’t show any error

JavaScript

enter image description here

Advertisement

Answer

You can vectorize solution different way – with numpy.where instead lambda and np.vectorize:

JavaScript

EDIT:

After some research for correct working need pass x, y to lambda and also change selecting by columns in lambda function like, because you pass 2 columns to function:

JavaScript
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement