Snorrlaxxx
Snorrlaxxx

Reputation: 168

How to drop a row in pandas dataframe if there is only word in a pandas column

How do we drop an entire row on pandas dataframe if there is an item in a column that only has one word

Example:

'the cat likes mice',
'the dog likes the cat',
'dog'

Return

'the cat likes mice',
'the dog likes the cat'

Upvotes: 1

Views: 38

Answers (1)

teepee
teepee

Reputation: 2714

How about using the pd.Series.str.contains method to look for spaces:

df = pd.DataFrame({'items': ['the cat likes mice',
                             'the dog likes the cat',
                             'dog']})

df = df[df['items'].str.contains(' ')]

Upvotes: 1

Related Questions