Question
In Python, which method in the Pandas library would you
use to replace NaN values in a DataFrame with the median value of each column?Solution
The fillna() method in Pandas is used to replace NaN values in a DataFrame. By passing df.median() as an argument to fillna(), we can replace missing values with the median value of each column. This approach is especially useful when missing values are suspected to deviate from the mean due to outliers, making median imputation a more robust choice. The Pandas fillna() method is highly flexible and frequently used in data cleaning to handle missing data without discarding rows or losing valuable information in other columns. Option A (df.fillna(df.mean())) is incorrect as it fills NaNs with the mean rather than the median. Option B (df.replace(df.median())) is incorrect because replace() is not used directly for filling NaN values. Option D (df.dropna(inplace=True)) is incorrect as it removes rows with NaNs instead of filling them. Option E (df.interpolate(method="median")) is incorrect as interpolate() does not directly support median filling.
At what moisture content do seeds generally maintain germination for one year under normal warehouse conditions?
Why is replication important in experimental design?
Animal drawn MB plough is known as
Which of the following is main objective of puddling in paddy?
What will be the most suitable word to be filled in blank “a” ?
Which of the following is not correct about zero tillage?
Tillers cut near base at 45° angle and developing buds or ripening grains chewed are the damaging symptoms of _____
According to CRIDA, the depth of deep tillage is ____
What is the full form of IFOAM?
Conversion of rotary motion into mechanical power to move the vehicle wheels is done by