0
df_downsampled[df_downsampled['attack_cat']=="DoS"]
Take all the dataframe 'df_downsampled' where the column 'attack_cat' has the value Dos.
Dataset: https://www.unsw.adfa.edu.au/unsw-canberra-cyber/cybersecurity/ADFA-NB15-Datasets/
colunas = ['srcip','sport','dstip','dsport','proto','state','dur','sbytes', 'dbytes','sttl','dttl',
'sloss','dloss','service','Sload','Dload','Spkts','Dpkts','swin','dwin','stcpb','dtcpb',
'smeansz','dmeansz','trans_depth','res_bdy_len','Sjit','Djit','Stime','Ltime','Sintpkt',
'Dintpkt','tcprtt','synack','ackdat','is_sm_ips_ports','ct_state_ttl','ct_flw_http_mthd',
'is_ftp_login','ct_ftp_cmd','ct_srv_src','ct_srv_dst','ct_dst_ltm','ct_src_ltm','ct_src_dport_ltm',
'ct_dst_sport_ltm','ct_dst_src_ltm','attack_cat','Label' ]
UNSW1 = pd.read_csv('/home/users/p02543/ddos/UNSW-NB15_1.csv',dtype={"srcip":object ,},names = colunas)
UNSW2= pd.read_csv('/home/users/p02543/ddos/UNSW-NB15_2.csv',dtype={"srcip":object ,},names = colunas)
UNSW3= pd.read_csv('/home/users/p02543/ddos/UNSW-NB15_3.csv',dtype={"srcip":object ,},names = colunas)
UNSW4= pd.read_csv('/home/users/p02543/ddos/UNSW-NB15_4.csv',dtype={"srcip":object ,},names = colunas)
UNSW = pd.concat([UNSW1,UNSW2,UNSW3,UNSW4])
previsores = UNSW.iloc[:,UNSW.columns.isin(('Sload','Dload',
'Spkts','Dpkts','swin','dwin','smeansz','dmeansz',
'Sjit','Djit','Sintpkt','Dintpkt','tcprtt','synack','ackdat','ct_srv_src','ct_srv_dst','ct_dst_ltm',
'ct_src_ltm','ct_src_dport_ltm','ct_dst_sport_ltm','ct_dst_src_ltm')) ].values# atributos previsores
There are two columns I want to "merge":
one is called "Label" and has value 1 when it is attack, and 0 otherwise.
In the 'attack_cat' column I am only interested when its value is 'Dos' (and in this case the value of the 'Label' column is 1)
Goal:
Create a new column named "Class" that:
Take ONLY the values from the 'Label' column when the value of attack_cat is 'Dos' (and the value of 'Label' is 1)
(there are other values in attack_cat that do not interest me)
Take ALL values from the 'Label' column when it is 0 (no attack)
How to do?
Hello, it’s a bit confusing. An example of a dataframe you have and what you want as a result would help.
– Miguel
@Miguel: I edited the question!
– Ed S