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.
Find the wrong number in the given number series.
7, 14, 29, 58, 117, 233, 469
1, 1.5, 3, 7.5, 22.5, 75, 315
In each of the following, one term is wrong. Find the WRONG term.
7, 15, 29, 58, 117, 235
Find the wrong number in the given number series,
121, 130, 116, 139, 103, 148
- Find the wrong number in the given number series.
3, 6, 10, 15, 21, 29 121, 118, 122, 115, 127, 112
1024Â Â 3072Â Â Â 384Â Â Â 1152Â Â Â 145Â Â Â 432
Find the wrong number in the given number series.
15, 19, 36, 99, 355, 1379Â
2, 10, 30, 64, 130, 222
Find the wrong number in the given number series.
3, 7, 22, 89, 445, 2675