Home > Software engineering >  Error : only integer scalar arrays can be converted to a scalar index How to solve?
Error : only integer scalar arrays can be converted to a scalar index How to solve?

Time:02-10

I try to convert breast canser dataset to a dataframe and to use it but i got following error;

TypeError: only integer scalar arrays can be converted to a scalar index

#Import library
from sklearn.datasets import load_breast_cancer
import pandas as pd
#Load dataset
cancer = load_breast_cancer()
#Convert the sklearn.dataset cancer to a DataFrame.
df=pd.DataFrame(cancer.data,columns =[cancer.feature_names])
df['target']=pd.Series(data=cancer.target,index=df.index)
display(df['target'])

CodePudding user response:

The dataset converts to a dataframe correctly. It seems to be an indexing issue, so I changed the last line to

df[["target"]]

and it worked for me.

  • Related