Igor K.
Igor K.

Reputation: 877

Filter rows based on values in column

This is my DataFrame

           date    time   ticker   price
495     20200324  100000   LKOH   4484.0
496     20200324  100000   LKOH   4481.5
500     20200324  100000   LKOH   4482.0
623     20200324  100001   LKOH   4482.0
679     20200324  100001   LKOH   4482.0
...          ...     ...    ...     ...    
986321  20200324  183954   LKOH   4498.5
986336  20200324  183955   LKOH   4497.0
986385  20200324  183956   LKOH   4498.5
986481  20200324  183958   LKOH   4497.0
986482  20200324  183958   LKOH   4497.0

I apply to it filter:

df = df[df['time'] <184000]

But I DONT want to filter data for rows with ticker 'USDRUB'
So I need something like:

df = df[if ticker != 'USDRUB' then use filter df['time'] <184000] 

How to write it correctly?

Upvotes: 0

Views: 37

Answers (1)

adir abargil
adir abargil

Reputation: 5745

try the or | operation:

df = df[(df['time'] <184000) | (df["ticker"] == 'USBROB')]

Upvotes: 2

Related Questions