I have read an entire column from a excel sheet into a dataframe. Each cell in that column has a bunch of words with numbers (like phone numbers). How do I loop the data frame and extract numbers using a specific pattern using regex.
I have tried the following code
for i in (df):
df.str.contains('(4[0-9]{12}([0-9]{3})|[25][1-7][0-9]{14}|6(011|5[0-9][0-9])[0-9]{12}|3[47][0-9]{13}')
I know my regex is wrong, but I am getting the following error.
Edit : I have updated my regex. The cells have the data like this
" Hello, I am trying to order something ... my card number is 45621.... ." I want to take out the card number and put it in a file.
Traceback (most recent call last):
File "c:/Program Files/Python37/Scripts/output.py", line 12, in <module>
df.str.contains('^f')
File "C:\Program Files\Python37\lib\site-packages\pandas\core\generic.py", line 5067, in __getattr__
return object.__getattribute__(self, name)
AttributeError: 'DataFrame' object has no attribute 'str'