'How can I fill null values of one Categorical variable by mode
Here in this data set, there are null values in 'History' columns and there are three category in Age ('Old', 'Young', Middle) in Age columns. I want to replace null values of History column with mode of each History columns based on the Age.
For exapmle:
I want to do like this If Age is 'Old' I want to replace null values of History column with 'Low' as it is mode for History column when Age is Old is Low.
I want to do same, replace null valus of History when Age is 'Middle' with 'High' as the mode of History is 'High' when Age is Midle.
Same thing want do with Age is 'Young' replace History null values with 'Low' as mode of History is 'Low' when Age is 'Young'.
How can I do that?
df.head()
Age Gender OwnHome Married Location Salary Children History Catalogs AmountSpent
0 Old Female Own Single Far 47500 0 High 6 755
1 Middle Male Rent Single Close 63600 0 High 6 1318
2 Young Female Rent Single Close 13500 0 Low 18 296
3 Middle Male Own Married Close 85600 1 High 18 2436
4 Middle Female Own Single Close 68400 0 High 12 1304
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
