For the single row case:

In [35]:

df.loc[(df[0]==101) & (df[1]==3)] = [[200,10]]
df
Out[35]:
     0   1
0  100   0
1  100   1
2  101   2
3  200  10
4  102   4
5  102   5

For the multiple row-case the following would work:

In [60]:

a = np.array(([100, 100, 101, 101, 102, 102],
                 [0,1,3,3,3,4]))
df = pd.DataFrame(a.T)
df
Out[60]:
     0  1
0  100  0
1  100  1
2  101  3
3  101  3
4  102  3
5  102  4
In [61]:

df.loc[(df[0]==101) & (df[1]==3)] = 200,10
df
Out[61]:
     0   1
0  100   0
1  100   1
2  200  10
3  200  10
4  102   3
5  102   4

For multi-row update like you propose the following would work where the replacement site is a single row, first construct a dict of the old vals to search for and use the new values as the replacement value:

In [78]:

old_keys = [(x[0],x[1]) for x in old_vals]
new_valss = [(x[0],x[1]) for x in new_vals]
replace_vals = dict(zip(old_keys, new_vals))
replace_vals
Out[78]:
{(100, 0): array([300,  20]),
 (101, 3): array([200,  10]),
 (102, 5): array([400,  30])}

We can then iterate over the dict and then set the rows using the same method as my first answer:

In [93]:

for k,v in replace_vals.items():
    df.loc[(df[0] == k[0]) & (df[1] == k[1])] = [[v[0],v[1]]]
df
     0  1
0  100  0
     0  1
5  102  5
     0  1
3  101  3
Out[93]:
     0   1
0  300  20
1  100   1
2  101   2
3  200  10
4  102   4
5  400  30
Answer from EdChum on Stack Overflow
Top answer
1 of 4
14

For the single row case:

In [35]:

df.loc[(df[0]==101) & (df[1]==3)] = [[200,10]]
df
Out[35]:
     0   1
0  100   0
1  100   1
2  101   2
3  200  10
4  102   4
5  102   5

For the multiple row-case the following would work:

In [60]:

a = np.array(([100, 100, 101, 101, 102, 102],
                 [0,1,3,3,3,4]))
df = pd.DataFrame(a.T)
df
Out[60]:
     0  1
0  100  0
1  100  1
2  101  3
3  101  3
4  102  3
5  102  4
In [61]:

df.loc[(df[0]==101) & (df[1]==3)] = 200,10
df
Out[61]:
     0   1
0  100   0
1  100   1
2  200  10
3  200  10
4  102   3
5  102   4

For multi-row update like you propose the following would work where the replacement site is a single row, first construct a dict of the old vals to search for and use the new values as the replacement value:

In [78]:

old_keys = [(x[0],x[1]) for x in old_vals]
new_valss = [(x[0],x[1]) for x in new_vals]
replace_vals = dict(zip(old_keys, new_vals))
replace_vals
Out[78]:
{(100, 0): array([300,  20]),
 (101, 3): array([200,  10]),
 (102, 5): array([400,  30])}

We can then iterate over the dict and then set the rows using the same method as my first answer:

In [93]:

for k,v in replace_vals.items():
    df.loc[(df[0] == k[0]) & (df[1] == k[1])] = [[v[0],v[1]]]
df
     0  1
0  100  0
     0  1
5  102  5
     0  1
3  101  3
Out[93]:
     0   1
0  300  20
1  100   1
2  101   2
3  200  10
4  102   4
5  400  30
2 of 4
6

The simplest way should be this one:

df.loc[[3],0:1] = 200,10

In this case, 3 is the third row of the data frame while 0 and 1 are the columns.

This code instead, allows you to iterate over each row, check its content and replace it with what you want.

target = [101,3]
mod = [200,10]

for index, row in df.iterrows():
    if row[0] == target[0] and row[1] == target[1]:
        row[0] = mod[0]
        row[1] = mod[1]

print(df)
🌐
Note.nkmk.me
note.nkmk.me › home › python › pandas
pandas: Replace values in DataFrame and Series with replace() | note.nkmk.me
January 17, 2024 - In pandas, the replace() method allows you to replace values in DataFrame and Series. It is also possible to replace parts of strings using regular expressions (regex). pandas.DataFrame.replace — pan ...
Discussions

python - how to replace values of selected row of a column in panda's dataframe? - Stack Overflow
i have train dataset which has 12 columns. I want to select Cabin column rows according to Pclass column's value 1. And then replace value of selected rows of Cabin column with 1. i did followin... More on stackoverflow.com
🌐 stackoverflow.com
How to replace values in one column with values from another dataframe
You can join the dataframes to accomplish this easily. Check this out. More on reddit.com
🌐 r/rprogramming
9
5
March 29, 2022
how to update a pandas dataframe column value, when a specific string appears in another column?
It's not something you'd really use .apply for. You would use boolean indexing, e.g. df['A'].str.contains('foo') would give you a Series of True/False values. You can then use .loc to set column(s) to a particular value for the True rows: df.loc[df['A'].str.contains('foo'), 'B'] = 'bar' More on reddit.com
🌐 r/learnpython
7
3
July 24, 2024
How to replace a particular Pandas dataframe value by location?
Check out this SO answer, the recommended way is to use pandas.DataFrame.set_value: DataFrame.set_value(index, col, value, takeable=False) Put single value at passed column and index So in your case this would be df.set_value(0, 'dog', 'dog11'). More on reddit.com
🌐 r/learnpython
4
1
June 30, 2016
🌐
Data to Fish
datatofish.com › replace-values-pandas-dataframe
How to Replace Values in a pandas DataFrame
# replace one specific value in a column df['column_a'] = df['column_a'].replace("x", "y") # replace multiple values (x, y) with one value (z) in a column df['column_a'] = df['column_a'].replace(["x", "y"], "z") # replace values (w, x) with other values (y, z) in a column df['column_a'] = df['column_a'].replace(["w", "x"], ["y", "z"]) # replace one specific value in the entire df df = df.replace("x", "y")
🌐
Pandas
pandas.pydata.org › docs › reference › api › pandas.DataFrame.replace.html
pandas.DataFrame.replace — pandas 3.0.6 documentation
For example, {'a': 1, 'b': 'z'} looks for the value 1 in column ‘a’ and the value ‘z’ in column ‘b’ and replaces these values with whatever is specified in value. The value parameter should not be None in this case. You can treat this as a special case of passing two lists except that you are specifying the column to search in.
🌐
GeeksforGeeks
geeksforgeeks.org › data analysis › python-pandas-dataframe-replace
Python | Pandas dataframe.replace() - GeeksforGeeks
regex : Whether to interpret to_replace and/or value as regular expressions. If this is True then to_replace must be a string. Otherwise, to_replace must be None because this parameter will be interpreted as a regular expression or a list, dict, or array of regular expressions. method : Method to use when for replacement, when to_replace is a list. ... Here, we are replacing 49.50 with 60. ... import pandas as pd df = { "Array_1": [49.50, 70], "Array_2": [65.1, 49.50] } data = pd.DataFrame(df) print(data.replace(49.50, 60))
Published: July 11, 2025
🌐
Statistics Globe
statisticsglobe.com › home › python programming language for statistics & data science › replace values of pandas dataframe in python (4 examples)
Replace Values of pandas DataFrame in Python | Set by Index & Condition
May 11, 2023 - In this Python tutorial you’ll learn how to exchange values in a pandas DataFrame. ... data = pd.DataFrame({'x1':range(1, 5), # Create example DataFrame 'x2':range(5, 1, - 1), 'x3':range(3, 7)}) print(data) # Print example DataFrame · As you can see based on Table 1, our example data is a DataFrame constituted of four rows and three variables. Example 1 demonstrates how to replace values in a certain pandas DataFrame column based on a row index position.
🌐
W3Schools
w3schools.com › python › pandas › ref_df_replace.asp
Pandas DataFrame replace() Method
import pandas as pd data = { "name": ... newdf = df.replace(50, 60) Try it Yourself » · The replace() method replaces the specified value with another specified value....
Find elsewhere
🌐
Pandas
pandas.pydata.org › pandas-docs › stable › reference › api › pandas.DataFrame.replace.html
pandas.DataFrame.replace — pandas 3.0.5 documentation
For example, {'a': 1, 'b': 'z'} looks for the value 1 in column ‘a’ and the value ‘z’ in column ‘b’ and replaces these values with whatever is specified in value. The value parameter should not be None in this case. You can treat this as a special case of passing two lists except that you are specifying the column to search in.
🌐
Favtutor
favtutor.com › articles › pandas-replace-column-values
Pandas DataFrame: Replace Column Values (with code)
December 15, 2023 - The Pandas library provides the .replace() method in Python to replace columns in a DataFrame. The .replace() method is a versatile way to replace values in a Pandas DataFrame.
🌐
Python Course
python-course.eu › numerical-programming › accessing-and-changing-values-dataframes.php
27. Accessing and Changing values of DataFrames | python-course.eu
Use at if you only need to get or set a single value in a DataFrame or Series." loc on the other hand can be used to access a single value but also to access a group of rows and columns by a label or labels. Another intestering question is about the speed of both methods in comparison. We will measure the time behaviour in the following code examples: ... When it comes to speed the answer is clear: we should definitely use at. ... Enjoying this page? We offer live Python training courses covering the content of this site. ... This method replaces values given in to_replace with value.
🌐
Data Science Parichay
datascienceparichay.com › home › blog › pandas – replace values in a dataframe
Pandas - Replace Values in a DataFrame - Data Science Parichay
April 27, 2022 - If you want to replace the values in-place pass inplace=True · Let’s look at some of the different use-cases of the replace() function through some examples. The replace() function replaces all occurrences of the value with the desired value.
🌐
Towards Data Science
towardsdatascience.com › home › latest › how to replace values in pandas
How to Replace Values in Pandas | Towards Data Science
January 16, 2025 - ... [OUT]:0 20 1 day 2 day 3 day 4 day ... 6428 day 6429 day 6430 22 6431 day Name: pickup_hour, Length: 6433, dtype: object · The select() function is pretty similar to the Pandas replace() method.
🌐
Finxter
blog.finxter.com › home › learn python blog › 5 best ways to replace values in pandas dataframe columns
5 Best Ways to Replace Values in Pandas DataFrame Columns - Be on the Right Side of Change
February 19, 2024 - This method applies a function along an axis of the DataFrame, allowing for custom replacement logic on a row-by-row basis. ... def custom_replace(value): if value == 'berry': return 'cherry' return value df['fruits'] = df['fruits'].apply(custom_replace) print(df)
🌐
CodeRivers
coderivers.org › blog › python-pandas-replace-row-values
Python Pandas Replace Row Values: A Comprehensive Guide - CodeRivers
February 22, 2026 - This can be done for one or multiple rows, and for one or multiple columns simultaneously. The replace method in pandas is the primary tool for performing value replacement operations.
🌐
Vultr Docs
docs.vultr.com › python › third-party › pandas › DataFrame › replace
Python Pandas DataFrame replace() - Replace Values | Vultr Docs
December 27, 2024 - Use replace() to swap a list of values with another list. ... Here, 1 is replaced by 11 and 3 by 33 across the entire DataFrame. Specify the changes you intend as a pair of lists inside the replace() method.
🌐
GeeksforGeeks
geeksforgeeks.org › python › replace-values-of-a-dataframe-with-the-value-of-another-dataframe-in-pandas
Replace values of a DataFrame with the value of another DataFrame in Pandas - GeeksforGeeks
July 23, 2025 - Here we selected the common 'Name' ... are replaced with 5 to 18 marks, rahul'marks are replaced with 20 to 19 marks, etc. Pandas isin() method is used to filter data frames....
🌐
Statology
statology.org › home › how to replace values in a pandas dataframe (with examples)
How to Replace Values in a Pandas DataFrame (With Examples)
September 27, 2022 - The following code shows how to replace multiple values in a single column: #replace 6, 11, and 8 with 0, 1 and 2 in rebounds column df['rebounds'] = df['rebounds'].replace([6, 11, 8], [0, 1, 2]) #view DataFrame print(df) team division rebounds 0 A E 1 1 A W 2 2 B E 7 3 B E 0 4 B W 0 5 C W 5 6 C E 12 · The following tutorials explain how to perform other common tasks in pandas: