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

'hasOwnProperty' in javascript -

How to put a lock and transaction on table using spring 4 or above using jdbcTemplate and annotations like @Transactional? -

How to understand 2 main() functions after using uftrace to profile the C++ program? -