[Python] Cannot use mean strategy with non-numeric data

Discussão em 'Python' iniciado por Stack, Maio 19, 2025.

  1. Stack

    Stack Membro Participativo

    I want to use imputation on my data but I get this error:

    Cannot use mean strategy with non-numeric data: could not convert string to float: 'RL'

    I know that while using impution the way I'm using I should make sure that the columns is numerical but I checked everything I get an error. Here is my code:

    # identifying columns with object data type
    cols_with_missing_object = [col for col in X.columns if X[col].isnull().any() and X.dtypes[col] =='object']
    # dropping these columns
    X.drop(cols_with_missing_object, inplace= True, axis= 1)

    # Trying to impute my numerical data ( it consists of three columns)
    my_imputer = SimpleImputer()
    X_imputed = pd.DataFrame(my_imputer.fit_transform(X))


    Thanks for your time

    Continue reading...

Compartilhe esta Página