python - Pandas: How to remove rows from a dataframe based on a list? -


i have dataframe customers "bad" rows, key in dataframe customerid. know should drop these rows. have list called badcu says [23770, 24572, 28773, ...] each value corresponds different "bad" customer.

then have dataframe, lets call sales, want drop records bad customers, ones in badcu list.

if following

sales[sales.customerid.isin(badcu)] 

i got dataframe precisely records want drop, if

sales.drop(sales.customerid.isin(badcu)) 

it returns dataframe first row dropped (which legitimate order), , rest of rows intact (it doesn't delete bad ones), think know why happens, still don't know how drop incorrect customer id rows.

you need

new_df = sales[~sales.customerid.isin(badcu)] 

Comments

Popular posts from this blog

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -