簡體   English   中英

將兩個 Pandas 數據框與一個公共列合並

[英]merging two pandas dataframe with one common column

我有兩個看起來像這樣的數據框:

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

來自終端的數據幀頭

我想加入他們,我嘗試了熊貓“合並”:

df_merge = pd.merge(df,df_,on='title)

但它不起作用,因為數據幀中的標題列的順序不同,所以當我嘗試它時,我在所有行中都得到了一個錯誤,因此是一個空的數據幀。 如何根據常見的“標題”列合並它們兩個?

合並數據幀如下所示:

df_merge = df.merge(df_, on='title')
left_table.merge(right_table, on='title')

就是這樣。 如果你有一個錯誤,你沒有提供太多的信息來查看它。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM