How to convert a Scikit-learn dataset to a Pandas dataset?

后端 未结 22 2138
清酒与你
清酒与你 2020-11-28 19:10

How do I convert data from a Scikit-learn Bunch object to a Pandas DataFrame?

from sklearn.datasets import load_iris
import pandas as pd
data = load_iris()
p         


        
22条回答
  •  死守一世寂寞
    2020-11-28 19:40

    Basically what you need is the "data", and you have it in the scikit bunch, now you need just the "target" (prediction) which is also in the bunch.

    So just need to concat these two to make the data complete

      data_df = pd.DataFrame(cancer.data,columns=cancer.feature_names)
      target_df = pd.DataFrame(cancer.target,columns=['target'])
    
      final_df = data_df.join(target_df)
    

提交回复
热议问题