简体   繁体   中英

Compare two lists & only keep rows with matching values

I have a list of asin numbers and a dataframe which has the column of asin numbers. So I want to compare the list with the asin number in the dataframe & just keep the rows which have matching asin numbers from the list.

Use .isin() :

df = df[df.asin.isin(asin_list)]

or

df = df.query("asin.isin(@asin_list)")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM