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.
According to the Reserve Bank of India (Transfer to Public Ownership) Act, 1948, which led to the nationalization of the Reserve Bank of India, what ha...
Severe undernutrition due to the deficiency of food and energy is termed as _________.
As per the recent announcement by the Reserve Bank of India (RBI), what is the updated per transaction limit for UPI Lite? (October 2024)Â
In the following question, select the missing number from the given alternatives.
45, 15, 60, 75, 135, ?
At Vaishali, the Second Buddhist Council was conducted by ________.
The court poet and minister of ______, Harisena, composed the Allahabad pillar Inscription or Prayaga Prashasti.Â
In which unit, noise pollution is measured?Â
Which Museum's former director was charged with money-laundering in an art trafficking case?
Which of the following statements about the functions of the State Finance Commission is/are correct?
1. It reviews the financial position of the...
__________has retained his Men's Singles title by winning 2018 Australian Open.