Nairda123
Nairda123

Reputation: 323

Python Pandas delete multiple rows based on column value

I am trying to delete some rows based on column values. I am using pandas.

I have four key words for which I want to check a particular column.

df_1[df_1['Item'] != 'YoY Growth'] I know this will delete a column that has 'YoY Growth' however I have not found an efficient way to combine all my key words into one line so I can delete all the rows containing any of the key words ?

I also tried using the method below but I am having some trouble with syntax

indexNames = df_1[ df_1['Customer'] == 'YoY Growth'].index

indexNames = df_1[ df_1['Customer'] == 'WoW Growth'].index

df_1.drop(indexNames)

Upvotes: 0

Views: 6630

Answers (1)

AlexTorx
AlexTorx

Reputation: 775

Simply do :

indexNames = df_1[df_1['Customer'].isin(['YoY Growth', 'WoW Growth'])].index
df_1.drop(indexNames)

Upvotes: 5

Related Questions