Python Forum
Converting Filter to If Else Statement and Count
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Converting Filter to If Else Statement and Count
#2
You don't need to use pure for-loop here,

# the number of rows where your condition is True
true_cnt = (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)).sum()

# The number of rows in df (Total)
len(df)

# Probably, you need this:
len(df) - true_cnt 
Reply


Messages In This Thread
RE: Converting Filter to If Else Statement and Count - by scidam - Jul-20-2020, 01:46 AM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020