Merge two data frames based on common column values in Pandas

后端 未结 3 665
陌清茗
陌清茗 2020-11-27 16:02

How to get merged data frame from two data frames having common column value such that only those rows make merged data frame having common value in a particular column.

3条回答
  •  迷失自我
    2020-11-27 16:28

    We can merge two Data frames in several ways. Most common way in python is using merge operation in Pandas.

    import pandas
    dfinal = df1.merge(df2, on="movie_title", how = 'inner')
    

    For merging based on columns of different dataframe, you may specify left and right common column names specially in case of ambiguity of two different names of same column, lets say - 'movie_title' as 'movie_name'.

    dfinal = df1.merge(df2, how='inner', left_on='movie_title', right_on='movie_name')
    

    If you want to be even more specific, you may read the documentation of pandas merge operation.

提交回复
热议问题