ENH: Allow update to use an on keyword. Allow one to many update. by jseabold · Pull Request #6604 · pandas-dev/pandas (original) (raw)

Scratch an itch I had. Use case

df = DataFrame([[np.nan, 'A'],
                [np.nan, 'A'],
                [np.nan, 'A'],
                [1.5, 'B'],
                [2.2, 'C'],
                [3.1, 'C'],
                [1.2,' B']], columns=['number', 'name'])

df2 = pd.DataFrame([[3.5, 'A']], columns=['number', 'name'])

df.update(df2, on='name')

The tests fail though because when you reset the index, the column order is not preserved and self = self[col_order] doesn't seem to do what I'd expect it to do. Maybe there's a better way to go about doing all of this?

Also, I dropped reindex_like because you were just iterating through columns of NaNs in other.