【发布时间】:2021-10-10 10:18:43
【问题描述】:
我有两个看起来像这样的数据框:
50 51 100 The Treasure of the Sierra Madre (1948)
51 52 98 Up (2009)
52 53 100 12 Angry Men (Twelve Angry Men) (1957)
53 54 100 The 400 Blows (Les Quatre cents coups) (1959)
title viewers_score number_of_viewers_ratings
0 12 Angry Men (Twelve Angry Men) (1957) 97 103672
1 The 39 Steps (1935) 86 23647
2 The Adventures of Robin Hood (1938) 89 33584
3 All About Eve (1950) 94 44564
4 All Quiet on the Western Front (1930) 89 17768
我想加入他们,我试过 pandas 'merge':
df_merge = pd.merge(df,df_,on='title)
但它不起作用,因为数据框中的标题列的顺序不同,所以当我尝试它时,我在所有行中都得到一个错误,因此一个空数据框。如何根据共同的“标题”列合并它们两者?
【问题讨论】:
-
您在两个数据框中都没有相似的标题,因此您得到空结果。例如,绿野仙踪在第一个数据帧中,但不在第二个数据帧中。
-
这不是完整的数据框,它有 100 行,我只显示前 5 行
-
然后发布这些重叠的。
-
我编辑了第一个数据框
-
合并成功,12 Angry Men 在第三个数据框中。您的数据中有错字、多余的空格或其他内容。