ip address(string) needs to be converted to integer
Ex) 256.256.256.256 -> 4294967295
"convert function"
def ip2int(ip):
packedIP = socket.inet_aton(ip)
return struct.unpack("!L", packedIP)[0]
string to int
DF_X_training['SourceIP'] = DF_X_training.SourceIP.apply(ip2int)
DF_X_testing['SourceIP'] = DF_X_testing.SourceIP.apply(ip2int)
DF_X_training['DestinationIP'] = DF_X_training.DestinationIP.apply(ip2int)
DF_X_testing['DestinationIP'] = DF_X_testing.DestinationIP.apply(ip2int)
Change format
DF_X_training['TimeStamp'] = pd.to_datetime(DF_X_training['TimeStamp'], format='%Y-%m-%d %H:%M:%S')
DF_X_testing['TimeStamp'] = pd.to_datetime(DF_X_testing['TimeStamp'], format='%Y-%m-%d %H:%M:%S')
Convert dates to values
DF_X_training['TimeStamp'] = DF_X_training['TimeStamp'].apply(lambda x: x.value)
DF_X_testing['TimeStamp'] = DF_X_testing['TimeStamp'].apply(lambda x: x.value)
Showing Results