0
votes

I am learning about the basics of pandas and scikit-learn and I came up with a doubt while doing an exercise. It gives me an error. The code should return a (569, 31) DataFrame, but it gives me the following errors:

ValueError: Wrong number of items passed 30, placement implies 31

ValueError: Shape of passed values is (569, 30), indices imply (569, 31)

The piece of code I have is the following:

data = pd.DataFrame(cancer.data, columns= np.append(cancer['feature_names'], ['target']))
print(data.describe())

The cancer.data has 30 columns and I want to append the ['target'] column, so I can convert the cancer dataset to a dataframe with 31 columns instead of 30.

1
it means that number of columns is greater than the width of the data - crayxt
Can you give an example of the data? - Swagga Ting

1 Answers

0
votes

Declare a list that is to be converted into a column,for example target=[1,2,3,...] and then use cancer.data['target'] = target