Fill missing values with means
AeoneaSoftware Engineer · Technical ScreenLast updated
This question evaluates proficiency in missing-data imputation and pandas DataFrame manipulation, testing skills in column-wise aggregation, group-wise operations, and edge-case handling within the Data Manipulation (SQL/Python) domain.
You are given a pandas DataFrame df with missing values in multiple numeric columns. Write a concise pandas expression to replace NaNs in each numeric column with that column's mean while leaving non-numeric columns unchanged. Also explain how you would: (a) perform the operation in-place, (b) compute and apply per-group means based on a key column (e.g., 'group'), and (c) skip columns whose values are all NaN.
Solution walkthrough is for members
Get the full walkthrough with reference code and complexity analysis, plus Kitty Coach at 300 messages a day. Hints, the code runner and community answers stay free.