Python Forum

Full Version: Filtered Row Count
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I am trying to get a row count for a filtered data frame.

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))

I have tried:

df.count()
len (filt)
df.shape

All of these return the count of rows for the entire data frame, not the count for the filtered results. How do I display the count for the remaining rows after filtration?
I believe that I have been making progress:

seriesObj = df.apply(lambda x: True if x['Type of breach'] != 'HACK' else False , axis=1)

numOfRows = len(seriesObj[seriesObj == True].index)

print('Number of Rows in dataframe in which Type of breach != HACK : ', numOfRows)

These lines of code will return a count for only a partial filter (1 out of 2). How do I write a code to also include the other filter as well (to include the keywords "bank accounts" or "social security number" in the other column of my dataset)?