Santiago Torres
Santiago Torres

Reputation: 85

Python pandas: oposite of pandas.Series.str.match

How to Determine if each string in a column does not start with a match of a regular expression.

I need to check when a Column does NOT equal a string.

I've found:

pandas.Series.str.match

And it is almost what I need, but I want to get True when the string is NOT a match

Upvotes: 1

Views: 236

Answers (2)

BENY
BENY

Reputation: 323226

You can check with pd.Series.str.startswith

df_sub = df[~df['col'].str.startswith('your str')]

Upvotes: 1

user17242583
user17242583

Reputation:

Just negate the mask returned by str.contains:

~df['col'].str.contains("Your string")

Upvotes: 1

Related Questions