Pandas Merge returns NaN

后端 未结 2 493
隐瞒了意图╮
隐瞒了意图╮ 2021-01-01 19:48

I have issues with the merging of two large Dataframes since the merge returns NaN values though there are fitting values. The two dfs are shaped like:

df1

相关标签:
2条回答
  • 2021-01-01 20:36

    Spent 2-3 hours trying to resolve this issue. Didn't rcv any error message but just NaN. Dtypes was the issue.

    0 讨论(0)
  • 2021-01-01 20:54

    You need same dtype of joined columns:

    #convert first or second to str or int
    MergeDat['Motor'] = MergeDat['Motor'].astype(str)
    #Motor['Motor'] = Motor['Motor'].astype(str)
    
    #MergeDat['Motor'] = MergeDat['Motor'].astype(int)
    Motor['Motor'] = Motor['Motor'].astype(int)
    

    #convert first or second to str or int
    #MergeDat['Motor'] = MergeDat['Motor'].astype(str)
    Motor['Motor'] = Motor['Motor'].astype(str)
    
    MergeDat['Motor'] = MergeDat['Motor'].astype(int)
    #Motor['Motor'] = Motor['Motor'].astype(int)
    
    
    MergeDat=MergeDat.merge(Motor,how="left")
    
    0 讨论(0)
提交回复
热议问题