1

I have to create a clean list wherein names with 'Trust' or 'Trustee' in rows get deleted.

I'm using the following code but i'm not getting the desired result ?

df_clean = df[~df['Row Labels'].str.contains('trusteeship')]

eg : if the 'Row Labels' contains a row with ABC Trust or XYTrusteeshipZ, then the whole row should get deleted.

df_clean = df[~df['Row Labels'].str.contains('Trust')]

df_clean = df[~df['Row Labels'].str.lower().str.contains('trust')]

3
  • 1
    Use df_clean = df[~df['Row Labels'].str.contains('Trust')] Commented Feb 22, 2021 at 7:48
  • @jezrael thanks but i have already tried it.. didn't help.. i'l add the screenshot for the same Commented Feb 22, 2021 at 7:55
  • df_clean = df[~df['Row Labels'].str.lower().str.contains('trust')] Commented Feb 22, 2021 at 7:57

1 Answer 1

1

You can match with case=False parameter for ignore lower/uppercase characters:

df_clean = df[~df['Row Labels'].str.contains('trust', case=False)]

Or first convert values to lowercase like mentioned @anon01 in comments:

df_clean = df[~df['Row Labels'].str.lower().str.contains('trust')]
Sign up to request clarification or add additional context in comments.

2 Comments

i tried this .. provided a snippet for the same as well
df_clean = df[~df['Row Labels'].str.contains('trust', case=False)] this worked.. thanks buddy @jezrael

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.