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
Post a Comment