how to categorize object feature into two classes in pandas

Viewed 25

My target feature in the dataset contains various classes, and I want to split them into only two classes. For clarification: my target--> DF['normal'].unique() gives array(['normal', 'neptune', 'warezclient', 'ipsweep', 'portsweep','teardrop', 'nmap', 'satan', 'smurf', 'pod', 'back', 'guess_passwd', 'ftp_write', 'multihop', 'rootkit','buffer_overflow', 'imap', 'warezmaster', 'phf', 'land','loadmodule', 'spy', 'perl'], I want to make them only two classes ['normal', 'Attack'] How to do so?

1 Answers

Does this work for you?

DF['normal_simplified'] = DF['normal'].apply(lambda x: 'normal' if x == 'normal' else 'Attack')
Related