I have a Dataset like the following
monthYear code
201601 11
201601 12
201601 12
201601 10
201602 null
201602 21
201602 21
201602 21
201603 null
When code is null I want to replace that with the code that appeared the most during the last month. For the above example, the first null will get replaced by 12 and the second one with 21.
So the result would be the following.
monthYear code
201601 11
201601 12
201601 12
201601 10
201602 12
201602 21
201602 21
201602 21
201603 21
How can I achieve this?