Pandas: How to delete rows based on some conditions?
Try this:
df = df.loc[df["Number"]!=202 & df["B"]!= 'True']
If type in column B is boolean, then change the string "true" to a boolean True.
For example, I've a table:





Number
B
Action
DateTime




1
161
False
send:
2021-10-20 13:10:18


2
202
False
get
2021-10-20 13:10:20


3
202
False
take
2021-10-20 13:10:21


4
161
False
reply
2021-10-20 13:12:25


5
202
True
send
2021-10-20 13:15:18


6
161
False
get
2021-10-20 13:15:20


7
161
False
take
2021-10-20 13:15:21


8
202
False
reply
2021-10-20 13:15:25




Here, True/False is based on whether column 'Action' has 'send' without colon or not. If 'send' then it's True, otherwise False.
I want to delete rows based on condition of a row which is True. So, delete rows if:
i) a column 'Number' has a same a number which corresponds to value True in column 'B', In this case: delete if Number== 202
ii)and if a column 'Datetime' is in range of 2 minutes of a column which corresponds to value True in column 'B'. Datetime corresponding to True value is '2021-10-20 13:15:18' and it's range of 2 is: [2021-10-20 13:13:18 ; 2021-10-20 13:17:18].
Overall, deleted rows should have a number=202 and which are in range [2021-10-20 13:13:18;2021-10-20 13:17:18]
New table should look like this:





Number
B
Action
DateTime




1
161
False
send:
2021-10-20 13:10:18


2
202
False
get
2021-10-20 13:10:20


3
202
False
take
2021-10-20 13:10:21


4
161
False
reply
2021-10-20 13:12:25


6
161
False
get
2021-10-20 13:15:20


7
161
False
take
2021-10-20 13:15:21




Sorry, if a question and task is not fully clear.