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
🌐
Pandas
pandas.pydata.org › docs › reference › api › pandas.DataFrame.apply.html
pandas.DataFrame.apply — pandas 3.0.1 documentation
>>> 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. In general, JIT compilation is only possible when the function passed to apply has type stability (variables in the function do not change their type during the execution).
🌐
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.assign() to a single column. The function is applied to the 'Total_Marks' column, and a new column 'Percentage' is formed with its help. ... # importing pandas library import pandas as pd # creating and initializing a list values= [['Rohan',455],['Elvish',250],['Deepak',495], ['Soni',400],['Radhika',350],['Vansh',450]] # creating a pandas dataframe df = pd.DataFrame(values,columns=['Name','Total_Marks']) # Applying lambda function to find # percentage of 'Total_Marks' column # using df.assign() df = df.assign(Percentage = lambda x: (x['Total_Marks'] /500 * 100)) # displaying the data frame df
🌐
Reddit
reddit.com › r/learnpython › pandas df: () got an unexpected keyword argument 'axis'
r/learnpython on Reddit: pandas df: <lambda>() got an unexpected keyword argument 'axis'
October 16, 2021 -
 df = pd.DataFrame([[4, 9]] * 3, columns=['A', 'B'])
 df.apply(lambda x: 1, axis=1)

This works just fine, it returns a dataframe with three rows where each row is 1

However this line

 df['A'].apply(lambda x: 1, axis=1)

gives the error <lambda>() got an unexpected keyword argument 'axis'. Shouldn't the behavior be the same?

It seems like in df.apply(lambda x: 1, axis=1) axis=1 is parsed as an argument to the pandas apply() method, but in df['A'].apply(lambda x: 1, axis=1) the axis=1 is getting parsed as being part of the lambda. Why is the parsing different just because I'm indexing a column?

🌐
stataiml
stataiml.com › posts › 47_not_use_pandas_apply
When to Use and Avoid `apply` in pandas DataFrame - stataiml
June 20, 2024 - You should use the apply function when you want to perform conditional complex manipulations on rows or columns of the DataFrame. The following example explains when to use the pandas apply function.
🌐
Apache
spark.apache.org › docs › latest › api › python › reference › pyspark.pandas › api › pyspark.pandas.DataFrame.apply.html
pyspark.pandas.DataFrame.apply — PySpark 4.1.1 documentation
You can omit type hints and let pandas-on-Spark infer its type. >>> df.apply(np.sum, axis=1) 0 13 1 13 2 13 dtype: int64 · >>> df.apply(max, axis=1) 0 9 1 9 2 9 dtype: int64 · Returning a list-like will result in a Series · >>> df.apply(lambda x: [1, 2], axis=1) 0 [1, 2] 1 [1, 2] 2 [1, 2] dtype: object ·
Find elsewhere
🌐
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 - Strategy 1.2: Write a better function, and apply that function. I’ve been working with a lot of canine health data lately, and one thing that has been fascinating to watch develop is the change “before COVID-19” vs. “after COVID-19”. One of the ways to cut the data, therefore, is to tag each row (I’m dealing with a huge trough of daily data) with “before” or “after” what I see as the inflection date: 3/6/2020 · So, like the Python/Pandas newb that I am, I wrote this function and then applied it to my multi-million row DF.
🌐
W3Schools
w3schools.com › python › pandas › ref_df_apply.asp
Pandas DataFrame apply() Method
import pandas as pd def calc_sum(x): return x.sum() data = { "x": [50, 40, 30], "y": [300, 1112, 42] } df = pd.DataFrame(data) x = df.apply(calc_sum) print(x) Try it Yourself »
🌐
W3Schools
w3schools.com › python › python_lambda.asp
Python Lambda
A lambda function can take any number of arguments, but can only have one expression.
🌐
DataCamp
datacamp.com › tutorial › pandas-apply
Pandas .apply(): What It Does, When It Helps, and Faster Alternatives | DataCamp
October 6, 2025 - Learn what Python pandas .apply is and how to use it for DataFrames. Learn how to iterate over DataFrames using the .apply() function today!
🌐
Saturn Cloud
saturncloud.io › blog › pandas-dataframe-applying-functions-to-all-columns
Pandas DataFrame Applying Functions to All Columns | Saturn Cloud Blog
January 6, 2024 - As you can see, the apply() method has applied the lambda function to each column in the DataFrame and returned a new DataFrame with the updated values. The apply() method is a versatile feature of Pandas that can be used in a wide variety of use cases.
🌐
Reddit
reddit.com › r/learnpython › i'm slightly addicted to lambda functions on pandas. is it bad practice?
r/learnpython on Reddit: I'm slightly addicted to lambda functions on Pandas. Is it bad practice?
June 11, 2025 -

I've been using python and Pandas at work for a couple of months, now, and I just realized that using df[df['Series'].apply(lambda x: [conditions]) is becoming my go-to solution for more complex filters. I just find the syntax simple to use and understand.

My question is, are there any downsides to this? I mean, I'm aware that using a lambda function for something when there may already be a method for what I want is reinventing the wheel, but I'm new to python and still learning all the methods, so I'm mostly thinking on how might affect things performance and readability-wise or if it's more of a "if it works, it works" situation.

🌐
Python
docs.python.org › 3 › library › itertools.html
itertools — Functions creating iterators for efficient looping
3 weeks ago - def groupby(iterable, key=None): # [k for k, g in groupby('AAAABBBCCDAABBB')] → A B C D A B # [list(g) for k, g in groupby('AAAABBBCCD')] → AAAA BBB CC D keyfunc = (lambda x: x) if key is None else key iterator = iter(iterable) exhausted = False def _grouper(target_key): nonlocal curr_value, curr_key, exhausted yield curr_value for curr_value in iterator: curr_key = keyfunc(curr_value) if curr_key != target_key: return yield curr_value exhausted = True try: curr_value = next(iterator) except StopIteration: return curr_key = keyfunc(curr_value) while not exhausted: target_key = curr_key curr_group = _grouper(target_key) yield curr_key, curr_group if curr_key == target_key: for _ in curr_group: pass
🌐
ProjectPro
projectpro.io › blog › how to apply lambda functions to python pandas?
How To Apply Lambda Functions To Python Pandas?
October 28, 2024 - For example, you can use the following ... values in every cell- ... In Pandas, applying lambda functions to multiple columns streamlines data transformations across various parts of a DataFrame....
🌐
The Carpentries
carpentries-incubator.github.io › python-business › 09-data_prep › index.html
Python for Business: Data Preparation techniques
June 19, 2020 - apply function will apply the lambda function on each value in the column, then return a pandas Series with return value of the lambda function.
🌐
Pandas
pandas.pydata.org › pandas-docs › version › 0.25.1 › reference › api › pandas.DataFrame.apply.html
pandas.DataFrame.apply — pandas 0.25.1 documentation
>>> df.apply(lambda x: [1, 2], axis=1, result_type='broadcast') A B 0 1 2 1 1 2 2 1 2 · index · modules | next | previous | pandas 0.25.1 documentation » · API reference » · DataFrame » ·
🌐
Spark By {Examples}
sparkbyexamples.com › home › pandas › pandas apply() function to single & multiple column(s)
Pandas apply() Function to Single & Multiple Column(s)
December 6, 2024 - # Apply function NumPy.square() ... # A B C #0 9 25 7 #1 4 16 6 #2 25 64 9 ... apply() is a Pandas DataFrame method used to apply a function along the axis of a DataFrame....
🌐
Medium
medium.com › @amit25173 › understanding-lambda-functions-in-pandas-e4588c53cc89
Understanding Lambda Functions in Pandas | by Amit Yadav | Medium
March 6, 2025 - Perfect with Pandas: Lambda works like magic with Pandas methods like apply() and map() for quick data transformations.
🌐
Techietory
techietory.com › home › data science › pandas apply function: transform your data
Pandas Apply Function: Transform Your Data with Custom Functions and Examples
1 month ago - Applying a function to a Pandas Series is the simplest use of apply(). It works element by element, transforming each value independently. Lambda functions (anonymous one-liner functions) are the most common companion to apply() on a Series: