I have 75 columns, and 300k captured network traffic CSV file. I am playing with data to apply ML. I need to convert IP addresses to 1 and 0 according to internal and external. So if it is
10.0.2.* > 0
others > 1
Is there an easy way to do this? I was doing the manually replace method.
df['SrcAddr'] = df['SrcAddr'].replace(['10.0.2.15','10.0.2.2'],[0,0,0])
IIUC, you can use:
or with a regex:
How it works: for each match this returns
True
, usingrsub(1)
we compute1-True -> 0
and for each non-match1-False -> 1
Alternative with
np.where
for using any value:example (as new column):