You need mask:

sample['PR'] = sample['PR'].mask(sample['PR'] < 90, np.nan)

Another solution with loc and boolean indexing:

sample.loc[sample['PR'] < 90, 'PR'] = np.nan

Sample:

import pandas as pd
import numpy as np

sample = pd.DataFrame({'PR':[10,100,40] })
print (sample)
    PR
0   10
1  100
2   40

sample['PR'] = sample['PR'].mask(sample['PR'] < 90, np.nan)
print (sample)
      PR
0    NaN
1  100.0
2    NaN
sample.loc[sample['PR'] < 90, 'PR'] = np.nan
print (sample)
      PR
0    NaN
1  100.0
2    NaN

EDIT:

Solution with apply:

sample['PR'] = sample['PR'].apply(lambda x: np.nan if x < 90 else x)

Timings len(df)=300k:

sample = pd.concat([sample]*100000).reset_index(drop=True)

In [853]: %timeit sample['PR'].apply(lambda x: np.nan if x < 90 else x)
10 loops, best of 3: 102 ms per loop

In [854]: %timeit sample['PR'].mask(sample['PR'] < 90, np.nan)
The slowest run took 4.28 times longer than the fastest. This could mean that an intermediate result is being cached.
100 loops, best of 3: 3.71 ms per loop
Answer from jezrael on Stack Overflow
🌐
GeeksforGeeks
geeksforgeeks.org › pandas › applying-lambda-functions-to-pandas-dataframe
Applying Lambda functions to Pandas Dataframe - GeeksforGeeks
July 15, 2025 - 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], ...
🌐
ProjectPro
projectpro.io › blog › how to apply lambda functions to python pandas?
How To Apply Lambda Functions To Python Pandas?
October 28, 2024 - You can use the following syntax to apply a Lambda function to a Pandas DataFrame using the .apply() method- ... You can use the following code to apply a lambda function to a DataFrame to double the values of each element in the 'Age' column using a Jupyter Notebook- ... Furthermore, you can use the following syntax to apply a lambda function to a Pandas DataFrame using the assign() method-
Discussions

How to properly apply a lambda function into a pandas data frame column - Stack Overflow
Copysample['PR'] = sample['PR'].apply(lambda x: 'NaN' if x < 90 else x) ... Find the answer to your question by asking. Ask question ... See similar questions with these tags. ... Developers are emotionally attached to their... What's the facts, Charity? How do I get my leaders to stop running teams Into... ... Help Shape the 2026 Developer Survey! ... 652 Create new column based on values from other columns / apply a function of multiple columns, row-wise in Pandas... More on stackoverflow.com
🌐 stackoverflow.com
python - How can I use the apply() function for a single column? - Stack Overflow
I have a pandas dataframe with multiple columns. I want to change the values of the only the first column without affecting the other columns. How can I do that using apply() in pandas? More on stackoverflow.com
🌐 stackoverflow.com
python - Creating a new pandas column by using lambda function on two existing columns - Stack Overflow
Releases Keep up-to-date on features we add to Stack Overflow and Stack Internal. ... Find centralized, trusted content and collaborate around the technologies you use most. Learn more about Collectives ... Bring the best of human thought and AI automation together at your work. Explore Stack Internal ... I am able to add a new column in Pandas by defining user function and then using apply. However, I want to do this using lambda... More on stackoverflow.com
🌐 stackoverflow.com
How to apply a lambda on pandas DataFrame column headers
You can pass multiple column names to get a "slice" >>> dfa[['BZ_Clicks', 'MF_Clicks']] BZ_Clicks MF_Clicks 0 40 50 1 50 30 2 60 120 [3 rows x 2 columns] This means you can pass in a comprehension directly >>> dfa[[col for col in dfa.columns if 'PX' in col]] BZ_PX_Joins MF_PX_Joins 0 10 5 1 30 12 2 25 25 [3 rows x 2 columns] More on reddit.com
🌐 r/learnpython
3
2
December 29, 2018
🌐
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. The .apply() function applies ...
🌐
Delft Stack
delftstack.com › home › howto › python pandas › apply lambda functions to pandas dataframe
How to Apply Lambda Function to Pandas DataFrame | Delft Stack
February 2, 2024 - We applied a Lambda function on multiple subjects columns such as Computer, Math, and Physics to calculate the obtained marks stored in the Marks_Obtained column. Implement the following example. ... import pandas as pd # nested list initialization values_list = [ ["Samreena", 85, 75, 100], ["Mehwish", 90, 75, 90], ["Asif", 95, 82, 80], ["Mirha", 75, 88, 68], ["Affan", 80, 63, 70], ["Raees", 91, 64, 90], ] # pandas dataframe creation df = pd.DataFrame(values_list, columns=["Student Names", "Computer", "Math", "Physics"]) # applying Lambda function dataframe = df.assign( Marks_Obtained=lambda x: (x["Computer"] + x["Math"] + x["Physics"]) ) # display dataframe print(dataframe)
🌐
Pandas
pandas.pydata.org › docs › reference › api › pandas.DataFrame.apply.html
pandas.DataFrame.apply — pandas 3.0.6 documentation
Only perform transforming type operations. ... Functions that mutate the passed object can produce unexpected behavior or errors and are not supported. See Mutating with User Defined Function (UDF) methods for more details. ... Returning a Series inside the function is similar to passing result_type='expand'. The resulting column names will be the Series index. >>> df.apply(lambda x: pd.Series([1, 2], index=["foo", "bar"]), axis=1) foo bar 0 1 2 1 1 2 2 1 2
🌐
Towards Data Science
towardsdatascience.com › home › latest › how to apply a function to columns in pandas
How To Apply a Function To Columns in Pandas | Towards Data Science
January 20, 2025 - On the other hand, in occasions where you need to apply a certain function over multiple columns, then you should probably use [pandas.DataFrame.apply()](https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.apply.html) method. For instance, let's suppose we need to apply the lambda function lambda x: x + 1 over the columns colA and colD.
Find elsewhere
🌐
Statology
statology.org › home › pandas: how to use apply & lambda together
Pandas: How to Use Apply & Lambda Together
June 23, 2022 - by Zach Bobbitt Published on Published on June 23, 2022 · You can use the following basic syntax to apply a lambda function to a pandas DataFrame:
🌐
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, as seen previously, import the pandas’ library as pd and then define the dataframe, which consists of multiple columns. Then we assign values to these columns of the dataframe and use the lambda function to give us the final result by using the equation as shown in the program. Hence, the program is implemented, and the output is as shown in the above snapshot. We can utilize the apply() capacity to apply the lambda capacity to the two lines and segments of a dataframe. On the off chance that the hub contention in the apply() work is 0, at that point, the lambda work gets applied to every segment, and in the event that 1, at that point, the capacity gets applied to each column.
Address: Unit no. 202, Jay Antariksh Bldg, Makwana Road, Marol, Andheri (East),, 400059, Mumbai
🌐
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)
🌐
Application-architect
application-architect.com › home › pandas › pandas - apply lambda function to column
Pandas - Apply Lambda Function to Column | Application Architect
September 13, 2025 - • Lambda functions can access multiple columns simultaneously using axis=1, enabling sophisticated transformations that depend on relationships between different fields in your dataset. The apply() method combined with lambda functions offers a straightforward approach to transform DataFrame ...
🌐
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.
🌐
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
🌐
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 - So, to remove this error from the Pandas dataframe, we have to add three years to every person’s age. We can do this with the apply() function in Pandas. apply() function calls the lambda function and applies it to every row or column of the dataframe and returns a modified copy of the dataframe:
🌐
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 - It’s often used to simplify code and make it more readable, and can be especially useful when working with data in a Pandas DataFrame. To apply a lambda function to a DataFrame, you can use the apply method. This method applies a function ...
🌐
TidyStat
tidystat.com › home › how to use lambda functions in python (pandas)
How to Use Lambda Functions in Python (Pandas)
January 20, 2025 - We can use apply() to call a lambda function, which will be applied to every row or column of the dataframe and returns a modified version of the original dataframe. If axis = 0 in apply(), the lambda function will be applied to each column.
🌐
Python Guides
pythonguides.com › lambda-function-pandas-dataframe
How to Use Lambda Functions in Pandas DataFrames
February 25, 2026 - However, for complex logic involving three or four different columns, it is my go-to solution. I often run into situations where I need to categorize data based on specific thresholds. For example, I might want to label US real estate prices as “High End” or “Mid Range” based on the current market. You can actually write a full if-else statement inside a single Lambda line. import pandas as pd # Sample US Real Estate Prices (Median values) data = { 'Listing_ID': [101, 102, 103, 104], 'State': ['CA', 'TX', 'NY', 'FL'], 'Price': [1200000, 450000, 950000, 380000] } df = pd.DataFrame(data) # I use an if-else inside the lambda to categorize the market df['Market_Type'] = df['Price'].apply(lambda x: 'High End' if x > 800000 else 'Mid Range') print(df)
🌐
The Carpentries
carpentries-incubator.github.io › python-business › 09-data_prep › index.html
Python for Business: Data Preparation techniques
June 19, 2020 - Lambda function is very handy in DataFrame manipulations. We will use 2 examples to demonstrate this. The first one is split one column to two columns with lambda function.