Forum Discussion
Power BI - How to use Python script to do a search and replace
Hi Anonymous ,
You can try to update the script as follow and check whether it works or not:
text1 = "X"
x = text1.replace("X", "Y")
print(x)
And it is easy to achieve it by using Table.ReplaceValue function in Power Query:
Replace multiple values in Power Query in one step
Best Regards
- Anonymous5 years agoNot applicable
Hi Anonymous and thank you for your reply!
I tried to use your script but unfortunately, it's not working for me. I have the same behavior as with the script I used previously.
And thanks for the Power Query process.
My goal with using python is to automate my data cleaning. This is for a report that I run every week and I am basically renaming a bunch of projects. I'd like to automate this part and just run a script to save some time.
- Anonymous5 years agoNot applicable
Hi Anonymous ,
Please update the script as below:
# 'dataset' holds the input data for this script import pandas as pd dataset['Text'] =pd.DataFrame(dataset['Text'].str.replace('X', 'Y', regex=False))The original data in my table as shown in below screenshot:
After applied the above script can become the below result:
Best Regards