合并功能不返回合并的数据框

时间:2018-06-23 06:30:49

标签: python pandas

我正在尝试将2个数据框与该行合并。

recommendations_df = recommendations_df.merge(anime_df, how = 'left', 
                                            left_on = 'name', 
                                            right_on = 'name')[['episodes', 
                                                                'user_rating',
                                                                'anime_id',
                                                                'genre',
                                                                "Score",
                                                                "name",
                                                                "type",
                                                                "members"]]

键“名称”在两个数据帧中,但是当我运行代码时,它可以工作,但是返回初始数据帧(命令),而没有我想要的列(片段...等)。

recommendations_df看起来像

    name    Score
0   Shinreigari Ghost Hound 0.946970
2   Wonderful Rush  0.882727
3   Saber Marionette J to X 0.836957
5   Hyouka  0.812808
6   Super Lovers    0.811879

和anime_df

    anime_id    name    genre   type    episodes    rating  members map_id
0   32281   Kimi no Na wa   Drama, Romance, School, Supernatural    Movie   1   9.37    200630.0    0
1   5114    Fullmetal Alchemist Brotherhood Action, Adventure, Drama, Fantasy, Magic, Mili...   TV  64  9.26    793665.0    1
2   28977   Gintama Action, Comedy, Historical, Parody, Samurai, S...   TV  51  9.25    114262.0    2
3   9253    Steins Gate Sci-Fi, Thriller    TV  24  9.17    673572.0    3
4   9969    Gintama 039 Action, Comedy, Historical, Parody, Samurai, S...   TV  51  9.16    151266.0    4

0 个答案:

没有答案