I want to modify only numeric variables in my data frame, i.e. impute missing values of numeric variables by median and those of factor variables by mode. To modify only numeric variables, I tried following:
xTrain.select_dtypes(include=numerics) = xTrain.select_dtypes(include=numerics).fillna(xTrain.mean(), inplace=True)
but it says:
SyntaxError: can't assign to function call
In fact, this solution just worked but I am not happy with it as it doesn't involve an assignment operation ('='). Moreover, this is a "private method" (i.e., an implementation detail) and is subject to change or total removal in the future. Was recommended to use with caution by answer here :
xTrain._get_numeric_data().fillna(xTrain.mean(), inplace=True)
Was thinking if there are alternative ways to select just numeric columns and impute them in the whole data, meaning modifying only part of the dataframe? Thanks in advance!