Your regex is matching on all - characters:

In [48]:
df_raw.replace(['-','\*'], ['0.00','0.00'], regex=True)

Out[48]:
       A          B
0   1.00        1.0
1  0.001  0.0045.00
2    NaN       0.00

If you put additional boundaries so that it only matches that single character with a termination then it works as expected:

In [47]:
df_raw.replace(['^-$'], ['0.00'], regex=True)

Out[47]:
      A       B
0  1.00     1.0
1    -1  -45.00
2   NaN    0.00

Here ^ means start of string and $ means end of string so it will only match on that single character.

Or you can just use replace which will only match on exact matches:

In [29]:

df_raw.replace('-',0)
Out[29]:
      A       B
0  1.00     1.0
1    -1  -45.00
2   NaN       0
Answer from EdChum on Stack Overflow
🌐
Pandas
pandas.pydata.org › docs › reference › api › pandas.Series.str.replace.html
pandas.Series.str.replace — pandas 3.0.5 documentation
>>> pat = r"(?P<one>\w+) (?P<two>\w+) (?P<three>\w+)" >>> repl = lambda m: m.group("two").swapcase() >>> ser = pd.Series(["One Two Three", "Foo Bar Baz"]) >>> ser.str.replace(pat, repl, regex=True) 0 tWO 1 bAR dtype: str
🌐
Pandas
pandas.pydata.org › docs › reference › api › pandas.DataFrame.replace.html
pandas.DataFrame.replace — pandas 3.0.5 documentation
>>> s.replace("a", None) 0 10 1 None 2 None 3 b 4 None dtype: object · When regex=True, value is not None and to_replace is a string, the replacement will be applied in all columns of the DataFrame.
Discussions

python - pandas: Dataframe.replace() with regex - Stack Overflow
0 Why can't I replace string for this symbol in DataFrame? 1 How would I change/remove 'non-printable' characters e.g  from df.columns values incorporating the regex statements already in place More on stackoverflow.com
🌐 stackoverflow.com
python .replace() regex - Stack Overflow
For anything in production, I would ... either regex or simple string search can accomplish. 2018-03-03T18:42:42.197Z+00:00 ... Save this answer. ... Show activity on this post. For this particular case, if using re module is overkill, how about using split (or rsplit) method as ... #!/usr/bin/python ... More on stackoverflow.com
🌐 stackoverflow.com
python - What does the regex parameter in .replace() function mean - Stack Overflow
And regex=True makes the replacing string be a regular expression More on stackoverflow.com
🌐 stackoverflow.com
pandas .replace not working
I got this to work .replace( '[\$,)]','', regex=True ). Still don't understand why my first method wasn't working... More on reddit.com
🌐 r/learnpython
6
4
December 31, 2015
🌐
Reddit
reddit.com › r/learnpython › why have to add regex = true to get .replace to work (pandas)
r/learnpython on Reddit: Why have to add regex = True to get .replace to work (pandas)
March 29, 2022 -

Hello Very new to pandas. Trying to replace ampersand in my excel file

Why did I have to add regex=True to get this to work. It wouldn’t update otherwise.

df = df.replace(‘%26’ , ‘&’ , regex = True)

🌐
Python documentation
docs.python.org › 3 › library › re.html
re — Regular expression operations — Python 3.14.7 ...
Source code: Lib/re/ This module provides regular expression matching operations similar to those found in Perl. Both patterns and strings to be searched can be Unicode strings ( str) as well as 8-...
🌐
Machine Learning Plus
machinelearningplus.com › blog › regex replace values using pandas
RegEx Replace values using Pandas - machinelearningplus
March 8, 2022 - These may include retrieving hashtags from a tweet, extracting dates from a text, or removing website links. Pandas replace() function is used to replace a string regex, list, dictionary, series, number in a dataframe.
Find elsewhere
🌐
Index.dev
index.dev › blog › regex-advanced-string-replacement-python
Python Regex Replace: How to Replace Strings Using re Module
The re.sub() function is the primary tool for performing string replacements with regex in Python. It allows you to specify a regex pattern to search for, a replacement string, and the target string where the replacement will occur.
🌐
Python documentation
docs.python.org › 3 › howto › regex.html
Regular expression HOWTO — Python 3.14.7 documentation
Author, A.M. Kuchling ,. Abstract: This document is an introductory tutorial to using regular expressions in Python with the re module. It provides a gentler introduction than th...
🌐
JanBask Training
janbasktraining.com › community › python-python › python-replace-regex
python .replace() regex | JanBask Training Community
May 7, 2025 - Trying to use .replace() with regex won't work and can lead to confusion. ... You’re absolutely right that `.replace()` does not support regular expressions and that’s a common point of confusion for many Python learners.
🌐
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,

🌐
Real Python
realpython.com › replace-string-python
How to Replace a String in Python – Real Python
October 22, 2025 - In this tutorial, you'll learn how to remove or replace a string or substring. You'll go from the basic string method .replace() all the way up to a multi-layer regex pattern using the sub() function from Python's re module.
🌐
Google
developers.google.com › google for education › python › python regular expressions
Python Regular Expressions | Python Education | Google for Developers
The re.sub(pat, replacement, str) function searches for all the instances of pattern in the given string, and replaces them.
🌐
Note.nkmk.me
note.nkmk.me › home › python › pandas
pandas: Replace values in DataFrame and Series with replace() | note.nkmk.me
January 17, 2024 - print(df.replace('(.*)li(.*)', r'\2-\1', regex=True)) # name age state point # 0 ce-A 24 NY 64 # 1 Bob 42 CA 24 # 2 e-Char 18 CA 70 # 3 Dave 68 TX 70 # 4 Ellen 24 CA 88 # 5 Frank 30 NY 57 · source: pandas_replace.py · For details on re.sub(), see the following article. Regular expressions with the re module in Python ·
🌐
Note.nkmk.me
note.nkmk.me › home › python
Replace Strings in Python: replace(), translate(), and Regex | note.nkmk.me
May 4, 2025 - In Python, you can replace strings using the replace() and translate() methods, or with regular expression functions like re.sub() and re.subn(). Additionally, you can replace substrings at specific p ...
🌐
Dive into Python
diveintopython.org › home › learn python programming › regex in python
RegEx in Python: Match and Replace Basics with Examples
May 3, 2024 - The re module in Python provides a method called sub() which stands for substitute. It's the cornerstone for performing python replaceall regex operations. The syntax is straightforward: re.sub(pattern, replacement, string).
🌐
Codedamn
codedamn.com › news › python
Python replace regex for searching and replacing strings
July 1, 2023 - In this example, the re.sub() function is used to replace all occurrences of 'codedamn' with 'CODEDAMN'. The output would be: Hello, CODEDAMN coders! Welcome to CODEDAMN community! The real power of regex comes with its ability to use special characters to construct search patterns, making it a vital tool for string manipulations in Python.