pandas merge dataframe with NaN (or “unknown”) for missing values

前端 未结 4 847
梦如初夏
梦如初夏 2021-02-05 01:27

I have 2 dataframes, one of which has supplemental information for some (but not all) of the rows in the other.

names = df({\'names\':[\'bob\',\'frank\',\'james\         


        
4条回答
  •  佛祖请我去吃肉
    2021-02-05 02:13

    I think you want to perform an outer merge:

    In [60]:
    
    pd.merge(names, info, how='outer')
    Out[60]:
         names position classification
    0      bob      dev            NaN
    1    frank      dev          thief
    2    james      dev            NaN
    3      tim      sys           good
    4  ricardo      sys            NaN
    5     mike      sys            NaN
    6     mark      sup          thief
    7     joan      sup            NaN
    8      joe      sup          thief
    

    There is section showing the type of merges can perform: http://pandas.pydata.org/pandas-docs/stable/merging.html#database-style-dataframe-joining-merging

提交回复
热议问题