If you have to use the "apply" variant, the code should be:

df['product_AH'] = df.apply(lambda row: row.Age * row.Height, axis=1)

The parameter to the function applied is the whole row.

But much quicker solution is:

df['product_AH'] = df.Age * df.Height

(1.43 ms, compared to 5.08 ms for the "apply" variant).

This way computation is performed using vectorization, whereas apply refers to each row separately, applies the function to it, then assembles all results and saves them in the target column, which is considerably slower.

Answer from Valdi_Bo on Stack Overflow
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ pandas โ€บ applying-lambda-functions-to-pandas-dataframe
Applying Lambda functions to Pandas Dataframe - GeeksforGeeks
July 15, 2025 - In this example, we will apply the lambda function Dataframe.apply() to single row. The lambda function is applied to a row starting with 'd' and hence square all values corresponding to it. ... # importing pandas and numpy libraries import pandas as pd import numpy as np # creating and initializing a nested list values_list = [[15, 2.5, 100], [20, 4.5, 50], [25, 5.2, 80], [45, 5.8, 48], [40, 6.3, 70], [41, 6.4, 90], [51, 2.3, 111]] # creating a pandas dataframe df = pd.DataFrame(values_list, columns=['Field_1', 'Field_2', 'Field_3'], index=['a', 'b', 'c', 'd', 'e', 'f', 'g']) # Apply function numpy.square() to square # the values of one row only i.e.
๐ŸŒ
Pandas
pandas.pydata.org โ€บ docs โ€บ reference โ€บ api โ€บ pandas.DataFrame.apply.html
pandas.DataFrame.apply โ€” pandas 3.0.6 documentation
Passing result_type='broadcast' will ensure the same shape result, whether list-like or scalar is returned by the function, and broadcast it along the axis. The resulting column names will be the originals. >>> df.apply(lambda x: [1, 2], axis=1, result_type="broadcast") A B 0 1 2 1 1 2 2 1 2 ยท Advanced users can speed up their code by using a Just-in-time (JIT) compiler with apply. The main JIT compilers available for pandas are Numba and Bodo.
Discussions

python - Using lambda functions with apply for Pandas DataFrame - Stack Overflow
I am sorry for asking such a trivial question, but I keep making mistakes when using the apply function with a lambda function that has input parameters. More on stackoverflow.com
๐ŸŒ stackoverflow.com
How to properly apply a lambda function into a pandas data frame column - Stack Overflow
Bring the best of human thought and AI automation together at your work. Explore Stack Internal ... Save this question. Show activity on this post. I have a pandas data frame, sample, with one of the columns called PR to which am applying a lambda function as follows: More on stackoverflow.com
๐ŸŒ stackoverflow.com
Lambda function in pandas
Lambdas are essentially one off functions. The first one looks like it's used to map difference between a mean and a Data point. A defined function would be something like the below that would then get plugged into the map function. Def func(p, review_points_mean): return p - review_points_mean Hope this works as I'm on mobile More on reddit.com
๐ŸŒ r/learnpython
4
3
June 11, 2020
I'm slightly addicted to lambda functions on Pandas. Is it bad practice?
Pandas apply is just a fancy for loop. A lot of people who work with pandas won't recommend apply unless you have to because is slower than a vectorized solution, but that doesn't mean that apply is bad. Apply with axis=0 is not that bad because you work with each column at a time, but if you are using axis=1, which is row by row, then that's really bad. Use that if you can't think or can't find a better solution. More on reddit.com
๐ŸŒ r/learnpython
26
39
June 11, 2025
๐ŸŒ
Medium
medium.com โ€บ @amit25173 โ€บ understanding-lambda-functions-in-pandas-e4588c53cc89
Understanding Lambda Functions in Pandas | by Amit Yadav | Medium
March 6, 2025 - Now, you might be wondering: โ€œIf I can just write regular functions, why bother with lambda?โ€ ... Perfect with Pandas: Lambda works like magic with Pandas methods like apply() and map() for quick data transformations.
๐ŸŒ
ProjectPro
projectpro.io โ€บ blog โ€บ how to apply lambda functions to python pandas?
How To Apply Lambda Functions To Python Pandas?
October 28, 2024 - We will explore the fundamentals of lambda functions, their application in Pandas Series and DataFrames, and their ability to handle multiple conditions and perform aggregate calculations, along with suitable examples.
๐ŸŒ
Analytics Vidhya
analyticsvidhya.com โ€บ home โ€บ learn how to use lambda functions in python easily and effectively
Learn How to Use Lambda Functions in Python Easily and Effectively
December 1, 2024 - We can use the apply() function to apply the lambda function to both rows and columns of a dataframe. If the axis argument in the apply() function is 0, then the lambda function gets applied to each column, and if 1, then the function gets applied to each row. apply() function can also be applied directly to a Pandas series:
๐ŸŒ
Medium
medium.com โ€บ @manishsingh7163 โ€บ use-lambda-functions-in-pandas-dataframes-for-efficient-data-processing-5800184d9415
Use Lambda Functions in Pandas DataFrames for Efficient Data Processing | by Manish Singh | Medium
January 1, 2023 - For example, letโ€™s say you have a DataFrame with a column of temperatures in Fahrenheit, and you want to convert them to Celsius. Hereโ€™s how you could do it using a lambda function: import pandas as pd # Create a sample DataFrame df = pd.DataFrame({'temperature (F)': [32, 212, 98.6, 68]}) # Use a lambda function to convert temperatures from Fahrenheit to Celsius df['temperature (C)'] = df['temperature (F)'].apply(lambda x: (x - 32) * 5/9) # Print the resulting DataFrame print(df)
๐ŸŒ
EDUCBA
educba.com โ€บ home โ€บ software development โ€บ software development tutorials โ€บ pandas tutorial โ€บ pandas lambda
Pandas Lambda | How Lambda Function Works in Pandas?
April 4, 2023 - In the above program, we first import the Pandas library as pd and then define the dataframe. After defining the dataframe, we assign the values and then use the lambda function and dataframe.assign to assign the equation of this function in order to implement it.
Address: Unit no. 202, Jay Antariksh Bldg, Makwana Road, Marol, Andheri (East),, 400059, Mumbai
Find elsewhere
๐ŸŒ
Saturn Cloud
saturncloud.io โ€บ blog โ€บ using-lambda-function-pandas-to-set-column-values
Using Lambda Function Pandas to Set Column Values | Saturn Cloud Blog
May 1, 2026 - A lambda function can be used as an argument for other functions or used to create a new function on the fly. To set column values in a Pandas DataFrame, we can use the .apply() function along with a lambda function.
๐ŸŒ
TidyStat
tidystat.com โ€บ home โ€บ how to use lambda functions in python (pandas)
How to Use Lambda Functions in Python (Pandas)
January 20, 2025 - You can use the combination of filter(), list(), and lambda functions to find the elements within a column in Pandas.
๐ŸŒ
Statology
statology.org โ€บ home โ€บ pandas: how to use apply & lambda together
Pandas: How to Use Apply & Lambda Together
June 23, 2022 - You can use the following basic syntax to apply a lambda function to a pandas DataFrame: df['col'] = df['col'].apply(lambda x: 'value1' if x < 20 else 'value2') The following examples show how to use this syntax in practice with the following pandas DataFrame:
๐ŸŒ
Python Guides
pythonguides.com โ€บ lambda-function-pandas-dataframe
How to Use Lambda Functions in Pandas DataFrames
February 25, 2026 - Most people use df.loc for filtering, but I often use Lambda within the .loc indexer for more dynamic filtering. This is especially helpful when I am chaining operations together and donโ€™t want to break the flow. Letโ€™s filter a list of US e-commerce orders to find only high-value shipments. import pandas as pd data = { 'Order_ID': [5001, 5002, 5003, 5004], 'Customer_State': ['Ohio', 'Oregon', 'Utah', 'Georgia'], 'Order_Value': [45.50, 1200.00, 300.25, 1500.00] } df = pd.DataFrame(data) # I use a lambda inside loc to filter for orders over $1,000 high_value_df = df.loc[lambda x: x['Order_Value'] > 1000] print(high_value_df)
๐ŸŒ
Medium
deallen7.medium.com โ€บ how-to-apply-lambda-apply-function-in-a-pandas-dataframe-a6bf5c74dc1c
How to Apply Lambda & Apply Function in a Pandas Dataframe | by David Allen | Medium
July 26, 2022 - Documentation and tutorials on Python, Pandas, Jupyter Notebook, and Data Analysis. ... The core learning here is to use cell magic and measure the execution time! Itโ€™s a terrific way to evaluate your code performance: ... Strategy 1: Write a function, and apply that function.
๐ŸŒ
Ryan Nolan Data
ryanandmattdatascience.com โ€บ home โ€บ python pandas โ€บ python pandas lambda function
Python Pandas Lambda Function - Ryan Nolan Data
August 7, 2025 - Using apply() with a lambda function is a flexible way to perform row-wise operations in pandas.
๐ŸŒ
Kahlee
kahlee.info โ€บ blog-posts โ€บ using-lambda-functions-with-pandas-python
Using lambda functions with pandas in Python
Lambda functions can also be applied to multiple columns in a single dataframe. Let's assume that the class takes two grades from the students, and a student will only pass if their average over both grades is at least 50. ... import pandas as pd dataset = {'Student': ['Joseph','Sally','Henry','Lisa','Alex','Michael'], 'Grade1': [90,92,37,52,43,65], 'Grade2': [87,43,52,64,57,53]} df = pd.DataFrame(data=dataset) df['Outcome'] = df.apply(lambda x: 'Pass' if (x['Grade1'] + x['Grade2'])/2 >= 50 else 'Fail', axis=1)
๐ŸŒ
Medium
infiniteknowledge.medium.com โ€บ how-to-apply-a-lambda-function-to-pandas-dataframe-3f97eb0cd556
How to apply a lambda function to pandas DataFrame? | by Panisetti Prudhviraj | Medium
February 6, 2023 - In this example, the lambda function takes an argument x and returns x**2. The apply method is used to apply this function to each element in the 'A' column of the DataFrame df.
๐ŸŒ
Spark By {Examples}
sparkbyexamples.com โ€บ home โ€บ pandas โ€บ pandas apply() with lambda examples
Pandas apply() with Lambda Examples - Spark By {Examples}
June 17, 2025 - pandas.DataFrame.apply() can be used along with the Python lambda function to apply a custom operation to all columns in a DataFrame. A lambda function is
๐ŸŒ
Javatpoint
javatpoint.com โ€บ applying-lambda-functions-to-pandas-dataframe
Applying Lambda functions to Pandas Dataframe - Javatpoint
Applying Lambda functions to Pandas Dataframe with tutorial, tkinter, button, overview, canvas, frame, environment set-up, first python program, etc.
๐ŸŒ
Reddit
reddit.com โ€บ r/learnpython โ€บ lambda function in pandas
r/learnpython on Reddit: Lambda function in pandas
June 11, 2020 -

Hi! So I'm trying to do a course on kaggle and I got stuck in using the lambda function - I'm not even sure to start in the first place.

For starters, kaggle introduces the lambda function with this line of code here, which makes me think that it's just like a normal function in math:

reviews.points.map(lambda p: p - review_points_mean)

However, as I looked through the tutorial, I didn't understand what was going on with the lambda function as it's being used to source out words from the data set as well. For example:

n_trop = reviews.description.map(lambda desc: "tropical" in desc).sum()

This was used as a way to sum up the number of times that the word "tropical" was used in the dataset. this also confused me with how you would use the lambda function itself as mentioned above that i thought it would be used just like a normal function in math.

My question is - how exactly is the lambda function from pandas being used in different ways? Because I don't understand what is going on in here. I've tried googling for answers online, but the pandas documentation does not answer my question. Thank you!