Consider a categorical variable in a pandas dataFrame, where some of the entries are NaN values, e.g.
User Name
1 Joe
2 nan
3 Joe
4 Mark
5 nan
6 Joe
I would like to replace the nan values by a user-defined function that preserves the frequency of the names, i.e., assigns weights [0.75, 0.25] to ['Joe', 'Mark'] respectively. This can be easily done with random.choices, how can I insert the values to the dataFrame with pandas?
value_countswithnormalize=Trueto get the weights, then set the null values withloc