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
๐ŸŒ
Python documentation
docs.python.org โ€บ 3 โ€บ howto โ€บ regex.html
Regular expression HOWTO โ€” Python 3.14.7 documentation
The optional argument count is the maximum number of pattern occurrences to be replaced; count must be a non-negative integer. The default value of 0 means to replace all occurrences. Hereโ€™s a simple example of using the sub() method.
๐ŸŒ
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
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
Why have to add regex = True to get .replace to work (pandas)
Df["colname"].str.replace("this", "that") This is how it's done More on reddit.com
๐ŸŒ r/learnpython
7
3
March 29, 2022
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
regex - Python string.replace regular expression - Stack Overflow
I have a parameter file of the form: parameter-name parameter-value Where the parameters may be in any order but there is only one parameter per line. I want to replace one parameter's 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.
๐ŸŒ
Index.dev
index.dev โ€บ blog โ€บ regex-advanced-string-replacement-python
Python Regex Replace: How to Replace Strings Using re Module
In this example, the word "World" is replaced with "Universe" using the regex pattern r"World". This is a straightforward use of re.sub(), but the true power of regex becomes apparent when you start using more complex patterns.
๐ŸŒ
Python documentation
docs.python.org โ€บ 3 โ€บ library โ€บ re.html
re โ€” Regular expression operations โ€” Python 3.14.7 ...
However, Unicode strings and 8-bit strings cannot be mixed: that is, you cannot match a Unicode string with a bytes pattern or vice-versa; similarly, when asking for a substitution, the replacement string must be of the same type as both the pattern and the search string. Regular expressions use the backslash character ('\') to indicate special forms or to allow special characters to be used without invoking their special meaning. This collides with Pythonโ€™s usage of the same character for the same purpose in string literals; for example, to match a literal backslash, one might have to write '\\\\' as the pattern string, because the regular expression must be \\, and each backslash must be expressed as \\ inside a regular Python string literal.
๐ŸŒ
Google
developers.google.com โ€บ google for education โ€บ python โ€บ python regular expressions
Python Regular Expressions | Python Education | Google for Developers
The replacement string can include '\1', '\2' which refer to the text from group(1), group(2), and so on from the original matching text. Here's an example which searches for all the email addresses, and changes them to keep the user (\1) but ...
Find elsewhere
๐ŸŒ
Machine Learning Plus
machinelearningplus.com โ€บ blog โ€บ regex replace values using pandas
RegEx Replace values using Pandas - machinelearningplus
March 8, 2022 - In this article, we explain how ... with examples ยท For using pandas replace function with regex, you need to define 3 parameters: to_replace, regex and value. to_replace: Denotes the value that has to be replaced in the dataframe or series. In the case of regular expressions, a regex pattern has to be passed. This pattern represents a generic sequence of characters. regex: For pandas to interpret the replacement as regular expression replacement, set it to True...
๐ŸŒ
Squash
squash.io โ€บ how-to-replace-regex-in-python
How To Replace Text with Regex In Python - Squash Labs
September 24, 2023 - In this example, the regex pattern [aeiou] matches any vowel in the input string. The occurrences of the vowels are replaced with asterisks using the re.sub() function. Related Article: How to Work with Encoding & Multiple Languages in Django ยท Another approach to replacing regex patterns in Python is by using regex groups and backreferences.
๐ŸŒ
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.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ python-substituting-patterns-in-text-using-regex
Python - Substituting patterns in text using regex - GeeksforGeeks
July 12, 2025 - Syntax: re.sub(pattern, repl, string, ... 1: Substitution of a specific text pattern In this example, a given text pattern will be searched and substituted in a string....
๐ŸŒ
EDUCBA
educba.com โ€บ home โ€บ software development โ€บ software development tutorials โ€บ python string tutorial โ€บ python regex replace
Python regex replace | Learn the Parameters of Python regex replace
May 13, 2024 - In Python, we use replace() function in the string concept, and it cannot be used for replacing the substring, or part of string were to replace() function is used to replace the entire string; hence to do this, we use regular expression which provides โ€œreโ€ module and to replace part of the string we use sub() function as we saw how simple it is to use this function for replacing the given pattern in the actual string to obtain the modified string. This is mainly used for replacing special characters with spaces or some other characters to make the string readable. This is a guide to Python regex replace.
Address: Unit no. 202, Jay Antariksh Bldg, Makwana Road, Marol, Andheri (East),, 400059, Mumbai
๐ŸŒ
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)

๐ŸŒ
Dive into Python
diveintopython.org โ€บ home โ€บ learn python programming โ€บ regex in python
RegEx in Python: Match and Replace Basics with Examples
May 3, 2024 - This powerful technique allows you to search for patterns within strings and replace them with desired text, making data manipulation smoother than ever. Whether you're working with data cleaning, processing, or even web scraping, understanding how to utilize Python string replace regex can significantly enhance your coding efficiency. Here's a concise guide with practical examples to get you started:
๐ŸŒ
w3resource
w3resource.com โ€บ pandas โ€บ series โ€บ series-replace.php
Pandas Series: replace() function - w3resource
Example - Regular expression 'to_replace': Python-Pandas Code: import numpy as np import pandas as pd df = pd.DataFrame({'X': ['bbb', 'fff', 'bii'], 'Y': ['abc', 'brr', 'pqr']}) df.replace(to_replace=r'^ba.$', value='new', regex=True) Output: X Y 0 bbb abc 1 fff brr 2 bii pqr ยท
๐ŸŒ
w3tutorials
w3tutorials.net โ€บ blog โ€บ replacing-specific-words-in-a-string-python
Python Regex Guide: How to Replace Specific Words in a String โ€“ Substituting $noun$ and $verb$ Placeholders
Pythonโ€™s built-in re module provides tools to work with regex. The star of the show for substitution is re.sub(), which replaces all non-overlapping matches of a pattern in a string. ... Our goal is to replace placeholders like $noun$ and $verb$ in a string (e.g., "I $verb$ the $noun$") with actual words (e.g., "I feed the dog").
๐ŸŒ
PythonTest
pythontest.com โ€บ python โ€บ regex-search-replace
Python regex Search and Replace Examples | PythonTest
I also may want to make a backup of example.txt first. We can all of those things, as Iโ€™ll show below. I think the most basic form of a search/replace script in python is something like this: import fileinput import re for line in fileinput.input(): line = re.sub('foo','bar', line.rstrip()) print(line) The fileinput module takes care of the stream verses filename input handling. The re (regex, regular expression) module has sub which handles the search/replace.