Reputation: 409
I have a CSV file that contains a few thousand rows, one column contains text values which sometimes are numbers. If the message column, in the example below, contains a number I want to remove the entire row.
The file is read in as a CSV, the table is a dataFrame, how I check if the message is a number and if it is then remove the entire row?
This is the original table:
name | message |
---|---|
John | Hello |
Steve | 25 |
Jane | Hi |
Janet | 89 |
I'd like it to look like this:
name | message |
---|---|
John | Hello |
Jane | Hi |
Thanks
Upvotes: 1
Views: 1182
Reputation: 71570
Just use str.contains
with the invert operator:
>>> df[~df['message'].str.contains('\d+')]
name message
0 John Hello
2 Jane Hi
>>>
Upvotes: 3