I have a list (list1) that looks like this:
  ['loc1','loc3','loc6'.....]
I also have a data frame (df1) that looks like this:
        Values    Proportion
loc1    200          10
loc2    50           20
loc3    100          30
loc4    60           45
loc5    70           12
loc6    80           11
loc7    10           10
.... 
I want to remove the rows where my index in the data frame matches values in the list. The resultant output file:
        Values    Proportion
loc2    50           20
loc4    60           45
loc5    70           12
loc7    10           10
.... 
My solution would be (but doesn't work).
reduced_file = set(df1.index) - list1
Try it like this:
df.loc[~df.index.isin(list1)]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With