I have inherited an old code file that has the following code. It seems the last line of the code below is removing all the open ( and close ) parentheses, and - character from the phone number field.
Question: But why it is using regex='\(' in .replace(regex='\(',value='') part of that last line? Some other online examples (such as here and here) I have seen don't seem to use regex keyword in their replacement function. What regex='\(' is doing in the replace function here?
import sqlalchemy as sq
import pandas as pd
import re
pw = dbutils.secrets.get(scope='SomeScope',key='sql')
engine = sq.create_engine('mssql+pymssql://SERVICE.Databricks.NONPUBLICETL:'+pw+'MyAzureSQL.database.windows.net:1433/TEST', isolation_level="AUTOCOMMIT")
pandas_df = pd.read_sql('select * from SQLTable1', con=engine)
pandas_df['MOBILE_PHONE'].replace(regex='\(',value='').replace(regex='\)',value='').replace(regex='\-',value='').str.strip()
repackage or tostring.replace()method. But in the inherited code, the replace() method is refering to pandas.pydata.org/docs/reference/api/… , seeregexkeyword.replace(regex='\)',value='')is it saying: my regex pattern is\). So find all substrings that match this pattern ( close parenthesis in this case) and remove it (i.e., replace it with empty string)?regex, is replaced byvalue.