Pandas merge creates unwanted duplicate entries

后端 未结 4 2132
天涯浪人
天涯浪人 2021-02-08 10:45

I\'m new to Pandas and I want to merge two datasets that have similar columns. The columns are going to each have some unique values compared to the other column, in addition to

4条回答
  •  悲&欢浪女
    2021-02-08 11:19

    did you try df.drop_duplicates() ?

    import pandas as pd
    
    dict1 = {'A':[2,2,3,4,5]}
    dict2 = {'A':[2,2,3,4,5]}
    
    df1 = pd.DataFrame(dict1)
    df2 = pd.DataFrame(dict2)
    
    df=pd.merge(df1,df2)
    df_new=df.drop_duplicates() 
    print df
    print df_new
    

    Seems that it gives the results that you want

提交回复
热议问题