Q:

Why does df['text'].str.contains('.') always return True?

I am writing some python code to replace punctuation in a column of strings in a pandas DataFrame. After replacement, I notice that testing existence of '.' within the resulting string always returns True.
I am using Python 3.7 and spotted this detail while using PyCharm. I have however, been able to reproduce the result in Jupyter Notebooks.

df = pd.DataFrame(['My string.'], columns=['Text'])
df['Text'] = df['Text'].str.replace('[^\w\s]', '')
print(df['Text'].str.contains('.'))

>>> 0  True

I would expect to False as the character '.' was replaced with the empty string. The string itself looks to have had its punctuation removed, but interestingly, the test of existence still returns True. Repeating this for other punctuation characters returns the expected value, False. Can anyone explain if this is expected behaviour?
Thanks in advance!

A:

print(df['Text'].str.contains('.',regex=False))
>>> 0  False

'.'is any character except line break in regex expresion , you need to tell to pandas if you want to use regex or not

