Yoav Vollansky
Yoav Vollansky

Reputation: 203

Getting a subset of a DataFrame that matches a condition?

I have a DataFrame of this form:

                  time_stamp      src_ip           dst_ip
...
...
2430355  2019-05-28 23:19:25  10.0.0.125    34.236.210.83
2430356  2019-05-28 23:19:25   10.0.3.58      104.24.0.13
2430357  2019-05-28 23:19:25  10.0.0.100    23.200.101.62
2430358  2019-05-28 23:19:25    10.1.3.2   172.224.12.136
2430359  2019-05-28 23:19:25  10.1.0.234     104.16.48.55
...
...

and I am trying to get rows that match a certain condition within a subset of that DataFrame:

data.iloc[67048:67058][data.iloc[67048:67058]['dst_ip'] == '159.45.170.143']

(the subset being [67048:67058] and the condition ['dst_ip'] == '159.45.170.143'])

This works fine but feels cumbersome. Is there a better way to perform this query?

Upvotes: 0

Views: 84

Answers (1)

BENY
BENY

Reputation: 323226

Update

data.iloc[67048:67058].query("dst_ip == '159.45.170.143'")

Upvotes: 1

Related Questions