Skip to content
Advertisement

Not finding a good regex pattern to substitute the strings in a correct order(python)

I have a list of column names that are in string format like below:

JavaScript

Now I want to add df[] with " ' " to each column name using regex and I did it which does that when the list has (wallet-phone) this kind of string it gives an output like this df[('wallet']-df['phone')]. How do I get like this (df['wallet']-df['phone']), Is my pattern wrong. Please refer it below:

JavaScript

gives:

JavaScript

Is the pattern wrong? Expected output:

JavaScript

I also tried ([^+-*/()[]'d]+) this pattern but it isn’t avoiding () or []

Advertisement

Answer

It might be easier to locate words and enclose them in the dictionary reference:

JavaScript
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement