I am sorry because this probably has an answer somewhere and I am just searching for the wrong stuff but here is my problem:
I have a pandas dataframe called data
and I want to create a decision tree using a module provided by my lecturer. This library comes with an example, where they use data.columns
to somehow get an index object that contains only the column names. They then proceed to use slicing to select only the descriptive features. Now my problem is that for my homework, I also need to select descriptive features, but I can't use slicing as I want to access some random columns. I tried to select the columns like this:
desc_columns = columns['workclass','education', 'marital-status', 'occupation', 'relationship', 'race', 'sex', 'native-country']
Which says that only integers are accepted as an index. Then I tried to access it like this:
desc_columns = columns[1,2,4,5,6,7,8,10]
Which gives me IndexError: too many indices for array
. Can someone tell me what this index thing is and how I can select arbitrary elements in it?