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.
Reduction in dry matter, decrease in amino acid content and accumulation of nitrates is the deficiency symptoms of:
MSP is a form of market intervention by the Government of India to insure agricultural producers against any sharp fall in farm prices. MSP is announced...
Which district among the following districts in Tripura has highest production of rubber during 2019-20 ?
The Rational equation is the simplest method to determine peak discharge from drainage basin runoff Q=CIA, C Stands for
 The science that deals with the aspects of meteorology having direct relevance to agriculture is called
What is the full form of fostac
“Bastard saffron” is term used for:
How many ATP molecules can be derived from each molecule of acetyl CoA that enter the Krebs' cycle?
Soil permeability is a broad term used to define the ability of the soil for:
What is the process of bees converting nectar into honey called?