0

I am having a numpy array of (200, 2000) and trying to convert it to a dataframe of 200 columns and 2000 rows.
I already have a list of column names that I would like to use in the dataframe, but I am struggling with an index error.

Code:

indexes = range(len(features_bow)+1)
features_bow_df = pd.DataFrame(features_bow, index=indexes,columns=features_bow.shape)
#features_bow.shape is the set column names that I have in the form of a list.

Error:

ValueError: Shape of passed values is (200, 2000), indices imply (2, 2000)

Any help would be appreciable.

JDurstberger
  • 3,747
  • 3
  • 28
  • 61
braj
  • 2,055
  • 25
  • 35
  • Can you post raw input data and code to reproduce your error, the error seems reasonably clear, the dimensions of your data, indices and columns don't match you need to post more info – EdChum Nov 30 '15 at 09:03
  • Data are little confidential, so will not be able to post it here. Let me put it this way. I have a numpy array of 200*2000. How can I convert it to a dataframe of 200 columns. – braj Nov 30 '15 at 10:00

1 Answers1

1

This looks like your columns have the wrong dimensions. .shape will return a tuple with two elements given the shape of your features_bow, hence you are getting the error that the column input has only length 2 as opposed to 200. Just put your column names into a list as seems your intention and you'll be fine. See also here on how to achieve this via slicing.

Community
  • 1
  • 1
Stefan
  • 35,233
  • 11
  • 66
  • 76