Given that this is the top Google result when searching for "Pandas replace is not working" I'd like to also mention that:

replace does full replacement searches, unless you turn on the regex switch. Use regex=True, and it should perform partial replacements as well.

This took me 30 minutes to find out, so hopefully I've saved the next person 30 minutes.

Answer from Reddspark on Stack Overflow
🌐
Reddit
reddit.com › r/learnpython › pandas .replace not working
r/learnpython on Reddit: pandas .replace not working
December 31, 2015 -

This is genuinely driving me crazy.

I have a data frame of unit prices in string format i'm trying to get them to a float

item_df['Unit Price'] = item_df['Unit Price'].replace('$','')

and all the '$' are still there.

THEN when I do this:

item_df['Unit Price'][1] = item_df['Unit Price'][1].replace('$','')

The '$' is gone from that index ಠ_ಠ. What the hell is going on?? Am I taking crazy pills or missing some fundamental concept?

Any help would be much appreciated.

Thanks,

Discussions

dataframe.replace() does not work on a subset of rows
My thought is that the last line ... and 02's replaced for all rows that have 'ab' == 'A'. But this does not work. No exception is thrown. Not quite sure what I'm doing wrong. Details # Paste the output here pd.show_versions() here · ------------------ commit: None python: 3.6.0.final.0 python-bits: 64 OS: Darwin OS-release: 16.4.0 machine: x86_64 processor: i386 byteorder: little LC_ALL: None LANG: en_US.UTF-8 LOCALE: en_US.UTF-8 pandas: 0.19.2 nose: ... More on github.com
🌐 github.com
4
March 11, 2017
Replace does not work Pandas
That’s just a statement, it would have been good to be asked nicely! df.loc[df.funding_total_usd == "-", "funding_total_usd"] = 0 More on reddit.com
🌐 r/learnpython
4
0
January 31, 2023
python - Why is Pandas replace() method not working? - Stack Overflow
I am trying to replace all columns ... isn't working: df = pd.read_csv(f_name, dtype="string") df = df[df.columns.dropna()] df[cols_int] = df[cols_int].replace({"[\$]": "", "[,]": ""}, regex=True) df[cols_int] = df[cols_int].astype(int) ... I'd appreciate any help! ... you need to use the replace for the string represenation of the series: df[cols_int].str.replace({"[\$]": "", "[,]": ""}, regex=True) -> place .str.in between. ... As of pandas 1.3, this bug should not occur ... More on stackoverflow.com
🌐 stackoverflow.com
Python Pandas replace() not working - Stack Overflow
I have some fields that have some junk in them from an upstream process. I'm trying to delete '\r\nName: hwowneremail, dtype: object' from a column that has this junk appended to an email address. More on stackoverflow.com
🌐 stackoverflow.com
May 22, 2017
🌐
GitHub
github.com › pandas-dev › pandas › issues › 44499
BUG: Pandas DataFrame replace() doesn't work if the dataframe has nullable boolean columns · Issue #44499 · pandas-dev/pandas
November 17, 2021 - Also please note both of the following work fine: import pandas as pd df = pd.DataFrame({"a": ["x", "y", "z", "w"], "b": [True, False, False, True]}).astype({"b":"bool"}) # notice 'bool' instead of 'boolean' df.replace("x", "X") and: df = pd.DataFrame({"a": ["x", "y", "z", "w"], "b": [True, False, False, True]}) df.replace("x", "X") the replace should complete successfully ·
Author: pandas-dev
🌐
Pandas
pandas.pydata.org › docs › reference › api › pandas.DataFrame.replace.html
pandas.DataFrame.replace — pandas 3.0.5 documentation
Note that column names (the top-level dictionary keys in a nested dictionary) cannot be regular expressions. ... This means that the regex argument must be a string, compiled regular expression, or list, dict, ndarray or Series of such elements. If value is also None then this must be a nested dictionary or Series. See the examples section for examples of each of these. ... Value to replace any values matching to_replace with.
🌐
GitHub
github.com › pandas-dev › pandas › issues › 15656
dataframe.replace() does not work on a subset of rows · Issue #15656 · pandas-dev/pandas
March 11, 2017 - My thought is that the last line of the above code block should result in a data frame that has all the 01's and 02's replaced for all rows that have 'ab' == 'A'. But this does not work. No exception is thrown. Not quite sure what I'm doing wrong. Details # Paste the output here pd.show_versions() here · ------------------ commit: None python: 3.6.0.final.0 python-bits: 64 OS: Darwin OS-release: 16.4.0 machine: x86_64 processor: i386 byteorder: little LC_ALL: None LANG: en_US.UTF-8 LOCALE: en_US.UTF-8 pandas: 0.19.2 nose: None pip: 9.0.1 setuptools: 27.2.0 Cython: None numpy: 1.12.0 scipy: No
Author: pandas-dev
🌐
Sharp Sight
sharpsight.ai › blog › pandas-replace
How to use the Pandas Replace Technique - Sharp Sight
February 6, 2024 - By default, the Pandas replace method returns a new dataframe. (This is the default behavior because by default, the inplace parameter is set to inplace = False.) If you set inplace = True, the method will return nothing, and will instead directly modify the dataframe that’s being operated on.
🌐
w3resource
w3resource.com › pandas › series › series-replace.php
Pandas Series: replace() function - w3resource
If to_replace is None and regex is not compilable into a regular expression or is a list, dict, ndarray, or Series.
Find elsewhere
🌐
Python Forum
python-forum.io › thread-33283.html
Pandas replace function not working on datafram with floats
April 12, 2021 - Hi, I am using Pandas' replace function and it works on one DataFrame but not on another and I don't understand why. I have tried many different solutions but nothing seems to work - Please take a look at the example code below: import pandas as p...
🌐
GitHub
github.com › pandas-dev › pandas › issues › 45372
BUG: Pandas.DataFrame.str.replace function fails silently for mixed data mixing strings and float/int and replaces with NaN · Issue #45372 · pandas-dev/pandas
January 14, 2022 - import pandas as pd import numpy as np list_of_random_numbers = np.random.randint(0,100,size=10) list_of_random_numbers_as_string = [str(x) for x in np.random.randint(0,100,size=10)] list_of_random_numbers_as_string[0] = list_of_random_numbers_as_string[0] + "'" df = pd.concat( [pd.DataFrame({'value':list_of_random_numbers}), pd.DataFrame({'value':list_of_random_numbers_as_string})], ignore_index=True) df['value'] = df['value'].str.replace("'", "") df.notnull().sum() When replacing a string in a column with mixed data, this replaces all non-string data with NaN without a warning (silent failur
Author: pandas-dev
🌐
YouTube
youtube.com › watch
How to Fix Pandas replace Not Working for Column Values - YouTube
Discover effective solutions for using `Pandas` to replace column values correctly when dealing with DataFrames. Learn step-by-step strategies to handle data...
Published: October 4, 2025
Views: 0
🌐
Codecademy
codecademy.com › docs › python:pandas › dataframe › .replace()
Python:Pandas | DataFrame | .replace() | Codecademy
August 23, 2022 - The original DataFrame values will not be replaced unless inplace is explicitly declared to True within the parameters. .replace() has the following parameters: In the following example, the .replace() method is used to replace ??? values in ...
🌐
Pandas
pandas.pydata.org › pandas-docs › stable › reference › api › pandas.Series.str.replace.html
pandas.Series.str.replace — pandas 3.0.5 documentation
Replacement string or a callable. The callable is passed the regex match object and must return a replacement string to be used.
🌐
GitHub
github.com › pandas-dev › pandas › issues › 26050
Problem with DataFrame.replace using None · Issue #26050 · pandas-dev/pandas
April 11, 2019 - It works fine if replaced with np.nan, but if anything, I would expect them to work very approximately the same. The expected output would be all strings matching the expression in replace to either be replaced with either None or NaN, or at least a warning message alerting for this behaviour. ... commit: None python: 3.6.8.final.0 python-bits: 64 OS: Darwin OS-release: 18.5.0 machine: x86_64 processor: i386 byteorder: little LC_ALL: None LANG: en_GB.UTF-8 LOCALE: en_GB.UTF-8 · pandas: 0.24.1 pytest: None pip: 19.0.3 setuptools: 40.6.2 Cython: None numpy: 1.16.0 scipy: 1.2.0 pyarrow: None xar
Author: pandas-dev
🌐
HAR Data Extractor
jonathansoma.com › course › foundations-2021 › replacing-with-str-replace-and-replace
Replacing with .str.replace and .replace
If you try to do that with .str.replace, you get an error: replace() missing 1 required positional argument: 'repl'. This means "You didn't tell me what to replace with what," even though it feels like you tried. # This will not work df['edited'] = df.original.str.replace({ "potatoes": "chocolate", "love": "hate" }) df
🌐
Medium
medium.com › @whyamit101 › understanding-pandas-replace-function-c2b0b7709233
Understanding pandas replace() Function | by why amit | Medium
February 10, 2025 - As you can see, the value 1 in column A was replaced by 100, while the rest of the values remained unchanged. This works for entire DataFrames, and pandas will only replace the values that match what you specify.
🌐
GeeksforGeeks
geeksforgeeks.org › data analysis › python-pandas-dataframe-replace
Python | Pandas dataframe.replace() - GeeksforGeeks
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