0

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)
1
  • 2
    df_1[~df_1['Customer'].isin(['YoY Growth', 'WoW Growth'])] ? Commented May 10, 2021 at 13:04

1 Answer 1

5

Simply do :

indexNames = df_1[df_1['Customer'].isin(['YoY Growth', 'WoW Growth'])].index
df_1.drop(indexNames)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.