I have missing non-numeric data in a pandas dataframe, is there a way of replacing the NaN with the value from a different row when another column matches? E.g:
tdf = pandas.DataFrame({
"id": [np.nan, 22, 22, 45, 45, 81],
"item": ["apple", "apple", "apple", "orange", "orange", "banana"]
})
id item
0 NaN apple
1 22 apple
2 22 apple
3 45 orange
4 45 orange
5 81 banana
So I would want to replace the id in the first row with 22 because the item is the same as row 1 or 2.