Skip to content Skip to sidebar Skip to footer

Blocking Seven Digit Numbers In String Pandas

Background I have the following sample df import pandas as pd df = pd.DataFrame({'Text':['This person num is 111-888-8888 and other', 'dont block 23 here'

Solution 1:

You can try this regex expression. ((?:[\d]-?){7,})

Regex Demo

Final block of code is this

df['New_Text'] = df['Text'].str.replace(r'((?:[\d]-?){7,})','**Block**')

Post a Comment for "Blocking Seven Digit Numbers In String Pandas"