Your replace format is off
In [21]: df = pd.DataFrame({'a':['Small', 'Medium', 'High']})
In [22]: df
Out[22]:
a
0 Small
1 Medium
2 High
[3 rows x 1 columns]
In [23]: df.replace({'a' : { 'Medium' : 2, 'Small' : 1, 'High' : 3 }})
Out[23]:
a
0 1
1 2
2 3
[3 rows x 1 columns]
Answer from Jeff on Stack OverflowGeeksforGeeks
geeksforgeeks.org › pandas › pandas-replace-multiple-values-in-python
Pandas Replace Multiple Values in Python - GeeksforGeeks
July 23, 2025 - One of Pandas most useful tools is the replace() method, which allows to substitute desired values with specified ones.
Top answer 1 of 7
94
Your replace format is off
In [21]: df = pd.DataFrame({'a':['Small', 'Medium', 'High']})
In [22]: df
Out[22]:
a
0 Small
1 Medium
2 High
[3 rows x 1 columns]
In [23]: df.replace({'a' : { 'Medium' : 2, 'Small' : 1, 'High' : 3 }})
Out[23]:
a
0 1
1 2
2 3
[3 rows x 1 columns]
2 of 7
28
In [123]: import pandas as pd
In [124]: state_df = pd.DataFrame({'state':['Small', 'Medium', 'High', 'Small', 'High']})
In [125]: state_df
Out[125]:
state
0 Small
1 Medium
2 High
3 Small
4 High
In [126]: replace_values = {'Small' : 1, 'Medium' : 2, 'High' : 3 }
In [127]: state_df = state_df.replace({"state": replace_values})
In [128]: state_df
Out[128]:
state
0 1
1 2
2 3
3 1
4 3
Replace multiple values in a single column Pandas
That error means that you can't use a data frame series as the key in a dictionary. All dictionary keys must be hashable. Moot point anyway, since you can't use str.replace that way. I'm guessing you were looking for str.translate, but that won't work either since it only works to replace characters. You need to make your own function that can convert a single string using a loop. More on reddit.com
How do I replace multiple unique values in a single column w/Pandas?
Panda's replace allows you to replace multiple values in a column using a dictionary - https://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.replace.html Something like this: df.replace({'street': {'Paper Street': 'Rock Street', 'Scissors Street': 'Rock Street'}}) More on reddit.com
Vectorized .str.replace() for multiple characters in pandas
I think my count and year columns are breaking because of the if statement excluding those two columns. More on reddit.com
Pandas - using .apply to replace multiple columns in a row?
I'm confused about how to set the following up. I have a data frame with say 10 columns I want to set up .apply so that for each row, if the first … More on reddit.com
11:32
How to Replace Values of Dataframes | Replace, Where, Mask, Update ...
03:39
Replace Multiple Values in a Pandas dataframe - YouTube
- YouTube
Replace Multiple Values in Several Columns of Data Frame in ...
Pandas : how to replace multiple values with one value python
02:29
How to REPLACE multiple values in a Pandas DataFrame in Python ...
Pandas
pandas.pydata.org › docs › reference › api › pandas.DataFrame.replace.html
pandas.DataFrame.replace — pandas 3.0.5 documentation
For a DataFrame a dict can specify that different values should be replaced in different columns. 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.
Python Guides
pythonguides.com › pandas-replace-multiple-values
Replace Multiple Values In Pandas DataFrame Using Str.Replace()
May 22, 2025 - # Replace values across the entire DataFrame df_replaced = df.replace({ 'California': 'CA', 'New York': 'NY', 1200: 'Low Sales', 1500: 'High Sales' }) print("\nDataFrame after multiple replacements:") print(df_replaced) Check out Convert DataFrame To NumPy Array Without Index in Python · The loc[] method in Python allows you to replace values based on conditions, which gives you more flexibility. Here’s an example with sales data categorization: import pandas as pd # Sample US sales data data = { 'Product': ['Laptop', 'Smartphone', 'Tablet', 'Monitor', 'Keyboard'], 'Sales': [1200, 1800, 950
Python Examples
pythonexamples.org › pandas-dataframe-replace-multiple-values
Pandas DataFrame - Replace Multiple Values
The syntax to replace multiple values in a column of DataFrame is · DataFrame.replace({'column_name' : { old_value_1 : new_value_1, old_value_2 : new_value_2}}) In the following example, we will use replace() method to replace 1 with 11 and 2 with 22 in column a. import pandas as pd df = ...
AskPython
askpython.com › home › replace multiple values in a dataset using pandas
Replace Multiple Values in a Dataset using Pandas - AskPython
February 16, 2023 - import pandas as pd data = pd.DataFrame([ ['Jack',25,'USA'], ['Rohan',20,'India'], ['Sam',23,'France'], ['Rini',19,'UK'], ['Tywin',16,'Ireland']], columns=['Name','Age', 'Country']) print (data) print('\n') new_data = data.replace({'Country':{'USA':'India'}}) print (new_data) updated_data = new_data.replace({'Age': {25:23, 16:18}, 'Name':{'Tywin':'Stark'}}) print('\n') print(updated_data)
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") ... That's it! You just learned how to replace values in a pandas DataFrame.
Reddit
reddit.com › r/learnpython › replace multiple values in a single column pandas
r/learnpython on Reddit: Replace multiple values in a single column Pandas
February 6, 2017 -
I am trying to replace parts of a single column string but keep running into an error. Please help anyone.
import pandas as pd
first = pd.read_csv('C:/Users/DATA INPUT.csv')
first['Address'] = str.replace({first['Address']: {'Ln': 'Lane','Dr': 'Drive','Rd' :
'Road','Ct': 'Court','Dr.': 'Drive',
'St': 'Street','Ave': 'Avenue',
'Crk':'Creek Way', 'Rdg' : 'Ridge'}})Error:
Traceback (most recent call last): File "C:\datainputcombo.py", line 8, in <module> File "C:\Users\Programs\Python\Python36-32\lib\site-packages\pandas\core\generic.py", line 831, in __hash__ ' hashed'.format(self.__class__.__name__)) TypeError: 'Series' objects are mutable, thus they cannot be hashed
Top answer 1 of 2
1
That error means that you can't use a data frame series as the key in a dictionary. All dictionary keys must be hashable. Moot point anyway, since you can't use str.replace that way. I'm guessing you were looking for str.translate, but that won't work either since it only works to replace characters. You need to make your own function that can convert a single string using a loop.
2 of 2
1
Unfortunately you can't give str.replace a dictionary mapping from abbreviation to the name you want to replace it with. You'll have to iterate over your dictionary key and value and replace one at a time: In [3]: first Out[3]: Address 0 12 Ln 1 13 Dr 2 14 Ave #mapping is the dictionary of abbeviation/name pairs i.e {'Ln': 'Lane', 'Dr': 'Drive' ...} In [5]: for abbrev, name in mapping.items(): ...: first['Address'] = first['Address'].str.replace(abbrev, name) In [6]: first Out[6]: Address 0 12 Lane 1 13 Drive 2 14 Avenue
PythonForBeginners.com
pythonforbeginners.com › home › pandas replace values in dataframe or series
Pandas Replace Values in Dataframe or Series - PythonForBeginners.com
January 9, 2023 - Instead of using the lists, you can pass a python dictionary to the replace() method to replace multiple values in a series with different values. For this, we will first create a dictionary that contains the values that have to be replaced as keys and the replacements as the associated value ...
Towards Data Science
towardsdatascience.com › home › latest › 2 different replace functions of python pandas
2 Different Replace Functions of Python Pandas | Towards Data Science
January 20, 2025 - Thanks to the flexibility of Pandas, we can do both replacements in a single operation. Each replacement is written as a key-value pair in the dictionary. ... Both "doc" and "eng" have been replaced. There is another way of replacing multiple values in a column, which is using Python lists to indicate values to be replaced and the new ones.
GeeksforGeeks
geeksforgeeks.org › data analysis › python-pandas-dataframe-replace
Python | Pandas dataframe.replace() - GeeksforGeeks
Replacing more than one value at a time. Using python list as an argument We are going to replace team "Boston Celtics" and "Texas" with "Omega Warrior" in the 'df' Dataframe. ... # importing pandas as pd import pandas as pd # Making data frame from the csv file df = pd.read_csv("nba.csv") # this will replace "Boston Celtics" and "Texas" with "Omega Warrior" df.replace(to_replace=["Boston Celtics", "Texas"], value="Omega Warrior")
Published: July 11, 2025
DataCamp
campus.datacamp.com › courses › writing-efficient-code-with-pandas › replacing-values-in-a-dataframe
Replace multiple values II | Python
In the DataFrame names, you are going to replace all the values on the left by the values on the right. ... Replace all the ethnicities by their respective alternative, as indicated above. Have a go at this exercise by completing this sample code. start_time = time.time() # Replace ethnicities as instructed names['Ethnicity'].replace([____,____, ____], [____,____,____], inplace=True) print("Time using .replace(): {} sec".format(time.time() - start_time))
IncludeHelp
includehelp.com › python › pandas-replace-multiple-values-one-column.aspx
Python - Pandas replace multiple values one column
October 3, 2023 - For this purpose, we will use the concept of a dictionary, we will first create a DataFrame and then we will replace the column by passing a dictionary inside replace method. In this dictionary, we will pass all the values in form of column values and the keys will represent the new values.
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: