How to retain column headers of data frame after Pre-processing in scikit-learn

后端 未结 4 1734
耶瑟儿~
耶瑟儿~ 2020-12-13 12:52

I have a pandas data frame which has some rows and columns. Each column has a header. Now as long as I keep doing data manipulation operations in pandas, my variable headers

4条回答
  •  难免孤独
    2020-12-13 13:21

    scikit-learn indeed strips the column headers in most cases, so just add them back on afterward. In your example, with X_imputed as the sklearn.preprocessing output and X_train as the original dataframe, you can put the column headers back on with:

    X_imputed_df = pd.DataFrame(X_imputed, columns = X_train.columns)
    

提交回复
热议问题