[英]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.我有一个 asin 数字列表和一个包含 asin 数字列的数据框。 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.
所以我想将列表与数据框中的 asin 编号进行比较,并只保留列表中具有匹配 asin 编号的行。
Use .isin()
:使用
.isin()
:
df = df[df.asin.isin(asin_list)]
or或者
df = df.query("asin.isin(@asin_list)")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.