这看起来很简单,但是很难做到正确。
对于给定的列表(索引),我想从数据框中获取列值。
下面,对于给定的item_ids
,从数据帧self.item_mean
中查找均值列表(与item_ids顺序相同)
(Pdb) item_ids.head()
0 1661
1 2791
2 77
3 3076
4 2862
Name: review_meta_id, dtype: object
(Pdb) df_item_mean.head()
review_meta_id mean
0 1 4.236750
1 10 3.898477
2 100 3.462879
3 1001 3.410140
4 1002 4.164352
(Pdb) item_means = df_item_mean.set_index('review_meta_id').loc[item_ids]
*** KeyError: "None of [Index(['1661', '2791', '77', '3076', '2862', '1469', '2794', '3379', '3430',\n '3157', '3077', '2224', '3172', '964', '2808', '2885', '1656', '2850'],\n dtype='object', name='review_meta_id')] are in the [index]"
(Pdb) type(item_ids)
<class 'pandas.core.series.Series'>