![]() |
And and Or Filters on Same Line - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: Data Science (https://python-forum.io/forum-44.html) +--- Thread: And and Or Filters on Same Line (/thread-28414.html) |
And and Or Filters on Same Line - RookToday - Jul-18-2020 Hello, I am trying to filter two columns in a dataset. One filter is a selection type, the other filter will be to include key words in a description. I do not understand the error codes that I am getting. Any ideas how I could get the program to show the filtered results? filt =[ (df['Type of breach']!='HACK') & (df['Description of incident'].str.contains('bank account' or 'social security number', na=False))] df[filt]
RE: And and Or Filters on Same Line - scidam - Jul-18-2020 Just remove square brackets. 'bank account' or 'social security number' will be evaluated to the first value, i.e. 'bank account', that is not what you really want. You probably want something like the following: filt =(df['Type of breach']!='HACK') & (df['Description of incident'].str.contains('bank account', na=False) | df['Description of incident'].str.contains('social security number', na=False)) RE: And and Or Filters on Same Line - RookToday - Jul-18-2020 Thank you very much. That seemed to work. |