I've run some tests here and I think I've found the answer.

My var self.name has a <class 'PyQt4.QtCore.QString'> type, since I'm getting it from a QtWidget. Someone, please, correct me if I'm wrong but from the tests I run and from the docs (http://doc.qt.io/qt-5/qstring.html#replace) it seems that the replace method in <class 'PyQt4.QtCore.QString'> happens inplace. Whereas for the Python str, it does not since python strings are immutable.

So, in short:

  • Python str: inplace=False (Python strings are immutable)
  • PyQt4.QtCore.QString: inplace=True

Anyway, hope this can be helpful

Answer from Eduardo on Stack Overflow
🌐
Stack Overflow
stackoverflow.com › questions › 59925498 › pandas-series-replace-inplace-true-not-working
python - pandas.series.replace() inplace = True not working - Stack Overflow
You can check this here : https://stackoverflow.com/a/50843478/9851541 Or, you can also check How to use the replace() method with keyword arguments to replace empty strings for your problem. Hope this helps! ... # create a dictionary 'mydict' mydict = {item:"" for item in punc} # replace the column 'FullDescription` in your data frame 'des', using the created dictionary des = des.replace({"FullDescription": mydict},regex=True) #if des is a series use des = des.replace(mydict,regex=True) return of inplace=True is None (ie, no need to assign back when using inplace replacement)
Discussions

'in-place' string modifications in Python - Stack Overflow
In Python, strings are immutable. What is the standard idiom to walk through a string character-by-character and modify it? The only methods I can think of are some genuinely stanky hacks related... More on stackoverflow.com
🌐 stackoverflow.com
Using replace() method
Strings are immutable. That is to say, after they've been created they cannot be modified. If you want to change them anyway, you have to make a copy that contains the changes you want. That's what .replace() does; it makes a new string that is a copy of the original with some portions of it replaced. As for why strings are immutable; there's a StackOverflow thread about that subject . On the other hand, lists are mutable (like most things). You can add, delete, modify, and rearrange its contents all you want, without having to create a new list to do it. So instead of creating a new list, .sort() just modifies the list in-place. More on reddit.com
🌐 r/learnpython
7
4
February 27, 2024
python - why pandas.replace inplace = True doesnt work - Stack Overflow
i have a Data Frame with the following columns A B C D 0 1.0 1.0 cob 3.0 1 1.0 1.0 hello 3.0 2 1.0 1.0 3.0 3 1.0 1.0 c 3.0 i am trying to replace the va... More on stackoverflow.com
🌐 stackoverflow.com
python - Why pandas DataFrame replace method does not work (inplace=True argument is used) - Stack Overflow
Add inplace=True to the accepted answer here: Replace all occurrences of a string in a pandas dataframe (Python) More on stackoverflow.com
🌐 stackoverflow.com
🌐
Reddit
reddit.com › r/learnpython › using replace() method
r/learnpython on Reddit: Using replace() method
February 27, 2024 -

Hi guys, I had a quick question about the exercise I was working on.

For using the replace() method and printing the result, we have to assign it to another variable and print that new variable.

sentence = sentence.replace(‘hey’, ‘hi’) print(sentence)

But for something such as the sort method we don’t need to assign it to a new variable and just use it straight up.

list = […] list.sort() print(list)

Why is it that some methods you need to assign it to a new variable, while others work while not assigning it to a new variable and the original is changed. Thank you.

Sorry about format, I’m on mobile.

🌐
CodeVsColor
codevscolor.com › python program to do inplace replace of string in a file - codevscolor
python program to do inplace replace of string in a file - CodeVsColor
September 5, 2020 - We are mainly using the first three parameters. If we pass inplace as True, it will do inplace replacement of file content. The backup takes one format of the backup file. This file is used to backup the content.
Find elsewhere
🌐
GeeksforGeeks
geeksforgeeks.org › python › in-place-string-modifications-in-python
In-Place String Modifications in Python - GeeksforGeeks
July 23, 2025 - Strings are immutable in Python, meaning their values cannot be modified directly after creation. However, we can simulate in-place string modifications using techniques such as string slicing and conversion to mutable data types like lists. String slicing is one of the most efficient ways for small changes. It creates a new string with modifications but is faster than other methods for simple replacements or rearrangements.
🌐
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.
🌐
Server Academy
serveracademy.com › blog › python-replace-function
Python Replace() Function Blog | Server Academy
November 14, 2024 - The method in Python is a powerful tool for working with strings, allowing you to replace parts of a string with new values. Whether you’re changing characters…
🌐
Stack Overflow
stackoverflow.com › questions › 68878873 › python-pandas-how-to-apply-inplace-true-for-replace-data-and-get-updated-csv
python pandas how to apply inplace = True for replace data and get updated csv - Stack Overflow
1 Substituting values in a CSV file using python · 0 Replace values in a csv file · 2 How to apply pandas.DataFrame.replace on selected columns with inplace = True? 1 Replace value in existing column .csv pandas · 4 Pandas DataFrame replace does not work with inplace=True ·
🌐
w3resource
w3resource.com › pandas › series › series-replace.php
Pandas Series: replace() function - w3resource
Series.replace(self, to_replace=None, value=None, inplace=False, limit=None, regex=False, method='pad')
🌐
DigitalOcean
digitalocean.com › community › tutorials › python-string-replace
Python String replace() | DigitalOcean
August 3, 2022 - Technical tutorials, Q&A, events — This is an inclusive place where developers can find or lend support and discover new ways to contribute to the community.
🌐
Pandas
pandas.pydata.org › docs › reference › api › pandas.Series.str.replace.html
pandas.Series.str.replace — pandas 3.0.6 documentation
When repl is a string, it replaces matching regex patterns as with re.sub(). NaN value(s) in the Series are left as is: >>> pd.Series(["foo", "fuz", np.nan]).str.replace("f.", "ba", regex=True) 0 bao 1 baz 2 NaN dtype: str
🌐
Pandas
pandas.pydata.org › docs › reference › api › pandas.DataFrame.replace.html
pandas.DataFrame.replace — pandas 3.0.6 documentation
For a DataFrame a dict of values can be used to specify which value to use for each column (columns not in the dict will not be filled). Regular expressions, strings and lists or dicts of such objects are also allowed. ... If True, performs operation inplace...
🌐
GeeksforGeeks
geeksforgeeks.org › python-string-replace
Python String replace() Method - GeeksforGeeks
October 28, 2024 - The isnumeric() method is a built-in method in Python that belongs to the string class. It is used to determine whether the string consists of numeric characters or not. It returns a Boolean value.
🌐
Python Central
pythoncentral.io › pythons-string-replace-method-replacing-python-strings
Python's string.replace() Method - Replacing Python Strings | Python Central
December 21, 2013 - Replacing Python Strings Often you'll have a string (str object), where you will want to modify the contents by replacing one piece of text with another. In Python, everything is an object - including strings. This includes the str object. Luckily, Python's string module comes with a replace() ...