![]() |
Filtered Row Count - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Filtered Row Count (/thread-28423.html) |
Filtered Row Count - RookToday - Jul-18-2020 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.shapeAll 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? RE: Filtered Row Count - RookToday - Jul-18-2020 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)? |