2017-10-12 43 views
0

我试图比较2个不同数据框中的一列,并得到一个错误。我的目标是确定df1中的playerID是否与df2中的playerID匹配。也不确定它是否有所作为,但每个数据帧中的数据长度不同。ValueError:只能比较2.7中相同标记的系列对象

这里是我的代码与数据帧的例子:

cleaned_hof_df = hof_df[(hof_df.inducted == 'Y') & (hof_df.category == 'Player')] 
cleaned_hof_df.reset_index(drop = True, inplace = True) 

cleaned_hof_df.head(3) 

cleaned_wins_losses_df = pitching_df[(pitching_df.W > 0) & (pitching_df.L > 0)] 
cleaned_wins_losses_df.reset_index(drop = True, inplace = True) 

cleaned_wins_losses_df.head(3) 

cleaned_hof_df.playerID == cleaned_wins_losses_df.playerID 

Here is my code with examples of the data frames

+1

您应该努力创建一个重现错误的示例,并将代码直接键入问题中,而不是发布代码的屏幕截图。有一个很好的[解释](https://meta.stackoverflow.com/a/285557/3639023)背后的理由。 – johnchase

+0

这很有道理。我在这方面是一个新人,但应该自己想出了一个。感谢您的高举。 – sadAndClueless72

回答

1

你的数据帧

cleaned_hot_df 

cleaned_win_losses_df 

有不同的n行的棕土,所以相应的系列

cleaned_hot_df.playerID 

cleaned_win_losses_df.playerID 

具有不同的长度。

所以你的两个系列没有相同的标签(这是你得到的错误)。

+0

所以,我无法比较两个不同长度的系列。我需要找到另一个解决方案。我将开始搜索。你有什么建议吗? – sadAndClueless72

+0

您可以使用'cleaned_win_losses_df [cleared_win_losses_df.playerID.isin(cleaned_hot_df.playerID)]'。 – MarianD