'How can I change Nan values to min value of given data in python
I want to change nan values with the min value of data in Python . But I need to do country match.
There are only nan values in daily_vaccinations column. I want to see minimum number of vaccined Argentinian instead of Nan. Also this number should change accordingly to the countries. I mean there should be the number of minimum Belgian vaccined instead of Belgium column.
Solution 1:[1]
Use the imputer from Sklearn and Numpy, in the missing_values parameter in the function specify the nan as shown here.
from sklearn.impute import SimpleImputer
import numpy as np
imputer = SimpleImputer(missing_values = np.nan, strategy= 'constant', fill_value = your_value)
# Then you can use the imputer like this
df[["my_column"]]=imputer.fit_transform(df[["my_column"]])
Also you can get the minimum value by this command:
min_value = df['my_column'].min()
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Omar |
