Search code examples
pythonregexpandassplitdata-cleaning

Custom Regex Query in an effiicient manner


So, I have a simple doubt but I am new to regex. I am working with a Pandas DataFrame. One of the columns contains the names. However, some names are written like "John Doe" but some are written like "John.Doe" and I need to write all of them like "John Doe". I need to run this on the whole dataframe. What is the regex query to fix this and in an efficient manner. Col Name = 'Customer_Name'. Let me know if more details are needed.


Solution

  • Try running this to replace all . with space, if that is your only condition:

    df['Customer_Name'] = df['Customer_Name'].str.replace('.', ' ')