I am trying to fill in missing values in my dataframe. However I want to fill the missing columns with a groupby statement. So here is what my dataframe looks like...
Number Other
1435 NaN
1435 NaN
1435 COOL
1817 NaN
1817 YES
So what I want to be able to do is basically just take the Max value or the last value that had data and fill the na for that specific number with that value..... So for example for 1435 I want to group it by number and then take the look for the max() in that column so it would find COOL and then fill all the NaN in the other column with COOL my final dataframe would look like this
Number Other
1435 COOL
1435 COOL
1435 COOL
1817 YES
1817 YES
what I have tried so far.
df["Number"] = df["Number"].fillna(value=df.groupby(['Number'])["Other"].max())
as well as
df["Number"] = df["Number"].fillna(value=df.groupby(['Number'])["Other"].last())
I think what I need to do is possibly sort them and then use last to get the value, but I cant seem to figure out how to do this and return the results I am looking for. any help would be greatly appreciated thanks.