Home > front end >  Filtering out a '.' from a python dataframe column
Filtering out a '.' from a python dataframe column

Time:11-09

I have a dataframe (df) that contains a column with urls. I want to filter out the values that do not contain a '.'.

I tried this:

df = df[~df['Domain'].str.contains('.')]

But the results still have some values with a value with no '.' in it. Any advice on how to filter out the specifically '.'?

CodePudding user response:

str.contains treats the input as a regular expression by default. Try escaping the dot:

df = df[~df['Domain'].str.contains('\.')]

Or, turn off the regex input by setting the regex flag to false:

df = df[~df['Domain'].str.contains('.', regex=False)]
  • Related