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
🌐
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)

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 - pandas applying regex to replace values - Stack Overflow
I have read some pricing data into a pandas dataframe the values appear as: $40,000* $40000 conditions attached I want to strip it down to just the numeric values. I know I can loop through and ap... 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
python - Pandas replace only working with regex - Stack Overflow
When you don't use regex=True the method will look for the exact match of the replace_to value. When you use regex=True it will look for the sub strings too. So your code works when you use that parameter. More on stackoverflow.com
🌐 stackoverflow.com
🌐
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.
🌐
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.
🌐
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.
Find elsewhere
🌐
Codedamn
codedamn.com › news › python
Python replace regex for searching and replacing strings
July 1, 2023 - To use regex in Python, we first need to import the re module. This can be done using the following line of code: ... One common use of regex is to find and replace certain parts of a string. This is accomplished using the re.sub() function in Python's re module.
🌐
Python Forum
python-forum.io › thread-2177.html
pandas dataframe.replace regex
Dear Pandas Experts, I am trying to replace occurences like 'United Kingdom of Great Britain and Ireland' or 'United Kingdom of Great Britain & Ireland' with just 'United Kingdom'. So I thought I use a regex to look for strings that contain 'United ...
🌐
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,

🌐
GitHub
github.com › pandas-dev › pandas › issues › 34993
BUG: replace method with regex=True does not work for byte string · Issue #34993 · pandas-dev/pandas
June 25, 2020 - import pandas as pd s = pd.Series([b'abc']) # This will replace "abc" with "123", output: # # 0 b'123' # dtype: object # print(s.replace(b'abc', b'123')) # But with regex=True, it doesn't work, output: # # 0 b'abc' # dtype: object # print(s.replace(b'abc', b'123', regex=True))
Author: pandas-dev
🌐
JanBask Training
janbasktraining.com › community › python-python › python-replace-regex
python .replace() regex | JanBask Training Community
May 7, 2025 - Allows pattern matching and replacement using regex. ... import re text = "Order123, Code456" new_text = re.sub(r'd+', '###', text) print(new_text) # Output: Order###, Code### ... Use .replace() for simple, direct substitutions.
🌐
StrataScratch
stratascratch.com › blog › how-to-replace-a-character-in-a-python-string
How to Replace a Character in a Python String - StrataScratch
October 18, 2024 - This is pandas equivalent to Python’s built-in function str.replace(), with some additional features: Series.str.replace(pat, repl, n=-1, case=None, regex=True)
🌐
GeeksforGeeks
geeksforgeeks.org › pandas › replace-values-in-pandas-dataframe-using-regex
Replace Values in Pandas Dataframe using Regex - GeeksforGeeks
October 9, 2025 - Explanation: The regex [nN]ew matches both "New" and "new", replacing them with "New_" across the entire DataFrame column. The apply() function lets you define a custom function that uses Python’s re module for pattern matching and string replacement.
🌐
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-...