NamAshena NamAshena - 3 months ago 12
Python Question

How to drop a row from Pandas dataframe?

This question is similar to this question posted before. However, I want to do something different, here is my

df
:

pos event
A 4 d5
A 2 d3
B 3 d3
B 6 u3


I want to get:

pos event
A 4 d5
A 2 d3
B 6 u3


I wrote this code but it is not working! any suggestion?

df.drop(df.ix[B]['event']=='d3', inplace=True)


My actual datafram is big and I want to drop the row that I want with index and value in event column.

Answer

You can use boolean indexing with | (or):

print (df[(df['event']!='d3') | (df.index != 'B')])
   pos event
A    4    d5
A    2    d3
B    6    u3