You could use Series.str.replace:

import pandas as pd

df = pd.DataFrame(['$40,000*','$40000 conditions attached'], columns=['P'])
print(df)
#                             P
# 0                    $40,000*
# 1  $40000 conditions attached

df['P'] = df['P'].str.replace(r'\D+', '', regex=True).astype('int')
print(df)

yields

       P
0  40000
1  40000

since \D matches any character that is not a decimal digit.

Answer from unutbu on Stack Overflow
🌐
GeeksforGeeks
geeksforgeeks.org › pandas › replace-values-in-pandas-dataframe-using-regex
Replace Values in Pandas Dataframe using Regex - GeeksforGeeks
October 9, 2025 - It scans the entire column for matches and replaces them in a single operation, making it both concise and efficient. In this example, city names starting with "New" or "new" are replaced with "New_".
🌐
Pandas
pandas.pydata.org › docs › reference › api › pandas.Series.str.replace.html
pandas.Series.str.replace — pandas 3.0.5 documentation
Method to replace occurrences of a substring with another substring. ... Extract substrings using a regular expression. ... Find all occurrences of a pattern or regex in each string.
🌐
Machine Learning Plus
machinelearningplus.com › blog › regex replace values using pandas
RegEx Replace values using Pandas - machinelearningplus
March 8, 2022 - For instance, you can replace all the cuss words in a text with special characters using regex replacement. Q1: To enable regular expression search in the replace function, what parameter should be enabled?
🌐
DataScientYst
datascientyst.com › replace-values-regex-pandas
How to replace values with regex in Pandas
December 2, 2021 - df['applicants'].replace(to_replace=r"([0-9,\.]+)(.*)", value=r"\1", regex=True) ... As you can see the code works as expected in case of a match. Otherwise it will keep the value.
🌐
Pandas
pandas.pydata.org › pandas-docs › stable › reference › api › pandas.DataFrame.replace.html
pandas.DataFrame.replace — pandas 3.0.5 documentation
This doesn’t matter much for value since there are only a few possible substitution regexes you can use. ... Dicts can be used to specify different replacement values for different existing values. For example, {'a': 'b', 'y': 'z'} replaces the value ‘a’ with ‘b’ and ‘y’ with ‘z’. To use a dict in this way, the optional value parameter should not be given.
🌐
Linux find Examples
queirozf.com › entries › pandas-dataframe-replace-examples
Pandas Dataframe: Replace Examples
October 4, 2020 - import pandas as pd df = pd.DataFrame({ 'name':['john','mary','paul'], 'age':[30,25,40], 'city':['new york','los angeles','london'] }) df.replace('jo.+','FOO',regex=True)
🌐
datagy
datagy.io › home › pandas tutorials › pandas dataframes › pandas replace() – replace values in pandas dataframe
Pandas replace() - Replace Values in Pandas Dataframe • datagy
March 2, 2023 - to_replace=: take a string, list, dictionary, regex, int, float, etc., and describes the values to replace ... Let’s dive into how to use the method, starting by loading a sample Pandas DataFrame.
🌐
IncludeHelp
includehelp.com › python › pandas-applying-regex-to-replace-values.aspx
Python - Pandas applying regex to replace values
# Importing pandas package import pandas as pd # Creating a dictionary d = {'Col':['$1100,000*','$40000 string created']} # Creating a dataframe df = pd.DataFrame(d) # Display Dataframe print("DataFrame :\n",df,"\n") # Using regex comparison df['Col'] = df['Col'].str.replace(r'\D+', '', regex=True).astype('int') # Display modified DataFrame print("Modified DataFrame:\n",df)
Find elsewhere
🌐
Pandas
pandas.pydata.org › docs › dev › reference › api › pandas.DataFrame.replace.html
pandas.DataFrame.replace — pandas 3.1.0.dev0 documentation
This doesn’t matter much for value since there are only a few possible substitution regexes you can use. ... Dicts can be used to specify different replacement values for different existing values. For example, {'a': 'b', 'y': 'z'} replaces the value ‘a’ with ‘b’ and ‘y’ with ‘z’. To use a dict in this way, the optional value parameter should not be given.
🌐
Pandas
pandas.pydata.org › pandas-docs › version › 0.22 › generated › pandas.Series.str.replace.html
pandas.Series.str.replace — pandas 0.22.0 documentation
>>> pd.Series(['foo', 'fuz', np.nan]).str.replace('f', 'b') 0 boo 1 buz 2 NaN dtype: object · When repl is a callable, it is called on every pat using re.sub(). The callable should expect one positional argument (a regex object) and return a string.
🌐
Note.nkmk.me
note.nkmk.me › home › python › pandas
pandas: Replace values in DataFrame and Series with replace() | note.nkmk.me
January 17, 2024 - In pandas, the replace() method allows you to replace values in DataFrame and Series. It is also possible to replace parts of strings using regular expressions (regex). pandas.DataFrame.replace — pan ...
🌐
Pandas
pandas.pydata.org › pandas-docs › version › 0.18.1 › generated › pandas.DataFrame.replace.html
pandas.DataFrame.replace — pandas 0.18.1 documentation
DataFrame.replace(to_replace=None, value=None, inplace=False, limit=None, regex=False, method='pad', axis=None)¶
🌐
Javatpoint
javatpoint.com › pandas-replace
Pandas.replace() - javatpoint
Pandas.replace() with What is Python Pandas, Reading Multiple Files, Null values, Multiple index, Application, Application Basics, Resampling, Plotting the data, Moving windows functions, Series, Read the file, Data operations, Filter Data etc.
🌐
Programiz
programiz.com › python-programming › pandas › methods › series-str-replace
Pandas str.replace() (With Examples)
import pandas as pd # create a Series products = pd.Series(['T-shirt 12', 'Jeans 30', 'Hat', 'Dress 8', 'Shoes 42']) # use str.replace() with regex to replace numeric sizes products_replaced = products.str.replace(r'\d+', 'SIZE', regex=True) print(products_replaced) Output · 0 T-shirt SIZE 1 Jeans SIZE 2 Hat 3 Dress SIZE 4 Shoes SIZE dtype: object · In the above example, the pattern r'\d+' matches sequences of digits in the product names.
🌐
Kanoki
kanoki.org › 2019 › 11 › 12 › how-to-use-regex-in-pandas
How to use Regex in Pandas | kanoki
November 12, 2019 - Replaces all the occurence of matched pattern in the string. We want to remove the dash(-) followed by number in the below pandas series object. The regex checks for a dash(-) followed by a numeric digit (represented by d) and replace that with an empty string and the inplace parameter set as True will update the existing series.
🌐
Sling Academy
slingacademy.com › article › pandas-replace-each-occurrence-of-regex-in-series
Pandas: Replace each occurrence of regex pattern in Series - Sling Academy
This basic example demonstrates replacing all occurrences of the letter ‘o’ with ‘0’. The ‘regex=True’ parameter tells Pandas that the first argument in the replace function is a regex pattern.
🌐
w3resource
w3resource.com › pandas › series › series-replace.php
Pandas Series: replace() function - w3resource
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)