DataFrame Does Not Include List Item

Question:

I have four lists that need to be turned into a DataFrame.

rule_name_list = ['More Than 3 Failed Login Attempts Within 1 Hour ', 'More Than 3 Failed Login Attempts Within 1 Hour ', 'More Than 3 Failed Login Attempts Within 1 Hour ', 'More Than 3 Failed Login Attempts Within 1 Hour ', 'More Than 3 Failed Login Attempts Within 1 Hour ', 'More Than 3 Failed Login Attempts Within 1 Hour ', 'Member Added to Security-Enabled Global Group', 'Security-Enabled Global Group Modified']
risk_score_list = [47, 47, 47, 47, 47, 47, 73, 73]
severity_list = ['medium', 'medium', 'medium', 'medium', 'medium', 'medium', 'high', 'high']
code_list = ['N/A', '4625', '4625', '4625', '4625', '4625', '4728', '4737']

When I create the DataFrame, the "More Than 3 Failed Login Attempts Within 1 Hour" rule is not included. I have no idea why.

`            def dataframe():
                df=pd.DataFrame({"Code":code_list,"Event":rule_name_list,"RiskScore":risk_score_list,"Severity":severity_list})
                # index = 1 * pd.RangeIndex(start=1, stop=2) #Add auto index
                #Group Columns
                df = df[df.Code.isin(event_code_list)] 
                    .groupby(["Code",'Event','RiskScore','Severity']) 
                    .agg(Detections = ("Event", len)) 
                    .reset_index()
                df = pd.DataFrame(df,columns=["Code",'Event','RiskScore','Severity','Detections'])
                return df
            final = dataframe()`

Output:

   Code                                          Event  RiskScore Severity  Detections
0  4728  Member Added to Security-Enabled Global Group         73     high           1
1  4737         Security-Enabled Global Group Modified         73     high           1

Intended Output:

   Code                                          Event  RiskScore Severity  Detections
0  4728  Member Added to Security-Enabled Global Group         73     high           1
1  4737         Security-Enabled Global Group Modified         73     high           1
2  4625  More Than 3 Failed Login Attempts Within 1 Hour       47     medium         6

Any help is appreciated.

Asked By: user21447606

||

Answers:

I strongly suspect that event_code_list contains only valid event codes and not the string N/A, so that record gets filtered out of your result.

Answered By: Benji York
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.