Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/359.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/elixir/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 比较具有相同标签的系列对象_Python_Pandas_Numpy - Fatal编程技术网

Python 比较具有相同标签的系列对象

Python 比较具有相同标签的系列对象,python,pandas,numpy,Python,Pandas,Numpy,我想使用一个数据集中的数据来过滤另一个数据集中的数据。 我的数据如下所示: ls.head() UserID Rating ISBN13 GoodreadsID Title Author 18266 2146832 5 0060525592 275000 Fire and Ice (Warriors, #2) Erin Hunter 18267 2119385 5 0060525592 275000 Fire and Ice (W

我想使用一个数据集中的数据来过滤另一个数据集中的数据。 我的数据如下所示:

ls.head()
UserID  Rating  ISBN13  GoodreadsID     Title   Author
18266   2146832     5   0060525592  275000  Fire and Ice (Warriors, #2)     Erin Hunter
18267   2119385     5   0060525592  275000  Fire and Ice (Warriors, #2)     Erin Hunter
18272   2117173     5   0060525592  275000  Fire and Ice (Warriors, #2)     Erin Hunter
18273   2117009     5   0060525592  275000  Fire and Ice (Warriors, #2)     Erin Hunter
18274   2106234     5   0060525592  275000  Fire and Ice (Warriors, #2)     Erin Hunter
还有我的第二个数据集:

data.head()

    UserID  Rating  ISBN13  GoodreadsID     Title   Author
150834  2131509     5   0143038419  19501   Eat, Pray, Love     Elizabeth Gilbert
59347   2113561     5   0374528373  4934    The Brothers Karamazov  Fyodor Dostoyevsky
37087   2122197     5   0316015849  41865   Twilight (Twilight, #1)     Stephenie Meyer
950201  2107691     3   044619817X  5931169     Santa Olivia (Santa Olivia, #1)     Jacqueline Carey
114404  2144218     3   0441015891  2233407     From Dead to Worse (Sookie Stackhouse, #8)  Charlaine Harris
1053208     2143953     4   0451463099  6582703     Unknown (Outcast Season, #2)    Rachel Caine
18290   2148946     5   0060525592  275000  Fire and Ice (Warriors, #2)     Erin Hunter
1585865     2140143     3   1594742812  4133366     The Curious Case of Benjamin Button: A Graphic...   Nunzio DeFilippis
1115470     2125069     0   0758234937  11796251    Cinnamon Roll Murder (Hannah Swensen, #15)  Joanne Fluke
484235  2108848     5   0553816713  15931   The Notebook (The Notebook, #1)     Nicholas Sparks
我想使用ls列['UserID'],并从第二个数据集('data')中选择所有这些用户

我试过:

data.loc[ls['UserID'] == data['UserID']]
…这让我

ValueError:只能比较标签相同的系列对象

我尝试了
排序索引()
重置索引()

我们会报答你的帮助。谢谢

试试这个:

df_merge = pd.merge(ls, data, on='UserID')
您还可以使用该方法(熊猫合并)的左\u和右\u参数

尝试以下操作:

df_merge = pd.merge(ls, data, on='UserID')

您还可以使用该方法(熊猫合并)的左\u和右\u参数

好主意!我没有想到什么?:-)好主意!我没有想到什么?:-)