0

I have a dataset, df, where I would like to remove any unnamed columns and remove rows that contain a specific value:

data

    Unamed  ID  Name
0   0       a   app23
1   1       b   db23
2   2       c   db233

desired

    ID  Name

    b   db23
    c   db233

I would like to remove any unnamed columns as well as remove any rows where the Name column values contain the string 'app'

doing

df.drop(df.index[df['Name'] == 'app'

Any suggestions are helpful

Lynn
  • 4,292
  • 5
  • 21
  • 44
  • Please provide the expected [MRE - Minimal, Reproducible Example](https://stackoverflow.com/help/minimal-reproducible-example). Show where the intermediate results deviate from the ones you expect. We should be able to paste a single block of your code into file, run it, and reproduce your problem. This also lets us test any suggestions in your context. We expect a minimal working example of the problem, including appropriate code to trace the internal operation. – Prune Mar 29 '21 at 02:01
  • [Include your minimal data frame](https://stackoverflow.com/questions/52413246/how-to-provide-a-reproducible-copy-of-your-dataframe-with-to-clipboard) as part of the example. – Prune Mar 29 '21 at 02:01
  • Stack Overflow is not intended to replace existing tutorials and documentation. Where exactly are you having trouble with the filtering and drops as given? – Prune Mar 29 '21 at 02:02

1 Answers1

2

Use str. contains to identify and drop any row with `app'. The use either drop columns or the iloc or loc accessor to select the rows and chain drop index method.

 df[~df['Name'].str.contains('app')].drop(columns=['Unamed']).style.hide_index()
wwnde
  • 26,119
  • 6
  • 18
  • 32