I'm trying to replace symbols from object in python, I used
df_summary.replace('\(|\)!,"-', '', regex=True)
![1]: https://i.stack.imgur.com/vozsS.jpg
but it didn't change anything.
CodePudding user response:
The replace function is not in place. This means that your dataframe will be unchanged, and the result is returned as the return value of the replac function. You can the the inplace parameter of replace:
df_summary.replace('\(|\)!,"-', '', regex=True, inplace=True)
Most of the pandas functions are note in place and require if needed either the inplace argument, or the assignement of the result to a new dataframe.
CodePudding user response:
You can either do
df_summary.replace('\(|\)!,"-', '', regex=True, inplace=True)
or
df_summary = df_summary.replace('\(|\)!,"-', '', regex=True)
When you only do df_summary.replace...
, this line returns you a pandas list. You forgot to save it. Please add comments to further assist you