fred.schwartz
fred.schwartz

Reputation: 2155

Filter pandas dataframe on columns if contains *

I have a pandas dataframe where some column values have a astrix *.

I want to remoeve rows that have this.

I have tries this but its not working

df.loc[~(df['col_name'].str.contains('*'))]

Upvotes: 1

Views: 71

Answers (1)

jezrael
jezrael

Reputation: 863166

Because * is special regex character add regex=False to Series.str.contains:

df.loc[~(df['col_name'].str.contains('*', regex=False))]

Or escape *:

df.loc[~(df['col_name'].str.contains('\*'))]

Upvotes: 5

Related Questions