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.
A bag contains 3 black and 9 white balls. One ball is drawn at random. What is the probability that the ball drawn is white?
...A bag contains 8 Green and 10 Red balls. One ball is drawn at random. What is the probability that the ball drawn is Red?
A bag contains 3 white balls , 5 blue balls , and 8 red balls . One ball is picked randomly from the bag and discarded. What is the probability of selec...
A box contains red, green, and blue balls. The probability of picking a blue ball at random is 1/4. The combined number of red and green balls is 15. If...
There are a total of 42 students (boys and girls) in a class. The probability of picking at least one boy when two students are picked from the class is...
A game consists of tossing three coins once and then rolling two dice. Find the probability of getting exactly one tail in the coin toss and a sum equal...
In a group of artists, there are 10 dancers and 8 singers. If four artists are to be selected at random, what is the probability that 2 dancers and 2 si...
Max has a 1/4 chance of failing his Quant test and a 4/5 chance of passing his Reasoning test. What is the probability that he fa...
- Raman has three children and he truthfully says, "at least one of my children is a girl." What is the probability that all of his children are girls?
- A bag contains x pink balls, (x + 2) blue balls and (x + 7) green balls. If probability of getting a blue ball is 1/9 more than that of getting a pink ball...