Drop rows in Pandas DataFrame by Column values (text)

Viewed 38

I want to return a new dataframe by dropping a row from dataframe using their respective text values. And only keeping ones that are blank (or whitespace). So far I can only find ways of either dropping NA, NULLS, by index or complete column. Please suggest way(s) how can I achieve this result.

Below is the value_count of column 'Category' -

                                4091
ZeroClicks                      1342
Duplicate                        257
ZeroClicksDuplicate              139
NoKeywordDuplicate                16
NoKeywordZeroClicksDuplicate      12
NoKeyword                          1
Name: Category, dtype: int64
1 Answers

try:

df.loc[df['col_containing_whitespace'].str.contains('^\s+$',na=False)] 

or

df.loc[df['col_containing_whitespace'].str.contains('^\s*$',na=False)] 

Related