Python数据筛选

现在有一组数据user_data如下

	user_id	                name  review_count  yelping_since	  useful	funny	  cool  
0	ntlvfPzc8eglqvk92iDIAw	Rafael	 553	2007-07-06 03:27:11	   628      225 	 227   
1	FOBRPlBHa3WPHFB5qYDlVg	Michelle 564	2008-04-28 01:29:25	   790	    316       400 
2	zZUnPeh2hEp0WydbAZEOOg	Martin	 60	    2008-08-28 23:40:05	   151	    125	      103      
3	QaELAmRcDc5TfJEylaaP8g	John	 206	2008-09-20 00:08:14	   233	    160       84       
4	xvu8G900tezTzbbfqmTKvA	Anne	 485	2008-08-09 00:30:27	  1265	    400	      512   

然后现在有一个类型为series的id_list包含了其中几个user_id.

	user_id
0	ntlvfPzc8eglqvk92iDIAw
1	zZUnPeh2hEp0WydbAZEOOg
2	V3t6VJNcO7yXslIJHG7nyA
3   QaELAmRcDc5TfJEylaaP8g

其中包含的id有的在数据集的use_id中存在,有的不在数据集的use_id中存在。

现在想通过这一列id_list进行过筛,找出user_id中包含id_list中存在的数据的数据,请问代码怎么写。

我尝试了很多

以下代码都不行

uuid = uuid.filter(id_list)

uuid = user_data[user_data['user_id'],]==id_list]

求大神给个解脱方案

uuid = user_data[user_data['user_id'] in id_list]

兄弟感谢回复,代码试了

TypeError: 'Series' objects are mutable, thus they cannot be hashed

以上答案不对,我采纳错了

uuid = user_data[user_data['user_id'].isin (id_list)]

不好意思,我没调试。这下我测试成功了。我想你本意是不想循环的,循环的简易写法是这样的

pd.concat([user_data[user_data['user_id']==i] for i in id_list])

可以list(id_list) 成列表