I need to filter a pandas Dataframe
by the range of ip addresses. Is it possible with out regular expressions?
Ex. From 61.245.160.0 To 61.245.175.255
Strings are orderable in python, so you should be able to get away with just that:
In [11]: '61.245.160.0' < '61.245.175.255'
Out[11]: True
Either boolean mask:
In [12]: df[('61.245.160.0' < df.ip) & (df.ip < '61.245.175.255')]
or take a slice (if ip were the index):
In [13]: df.loc['61.245.160.0':'61.245.175.255']
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With