Pandas: Filling NA values to be filled based on distribution of existing values

Viewed 4328

I have a pandas data-frame in which one column sign up has multiple null values. The sign up column has categorical values that includes multiple OS such as iOS, android, web etc. I would like to fill the NA values from the existing OS values but the NA values should be filled as per the existing distribution of OS values.

Example: Lets say, the dataset has OS values count distribution as follows:

signup
android web    14
ios web        16
mac            5
other          3
windows        6
Name: id, dtype: int64

I would like to fill the NA values based on the above distribution of the distinct OS values. The reason that I would like to do is to maintain the current distribution as filling with Mode value would likely to skew the results. Can someone help on how to achieve this.

3 Answers
Related