abjer / sds

Social Data Science - a summer school course
https://abjer.github.io/sds
18 stars 34 forks source link

Index problem. #14

Closed Helena1103 closed 6 years ago

Helena1103 commented 6 years ago

ex. 13.1.3

KeyError: ['.., ,...'] not in index.

Someone who has solved the index problem in this exercise?

Krier commented 6 years ago

To use indexes you need a DataFrame. Make sure the data that you work with is in a Pandas DataFrame. I it is already in a DataFrame, try to reindex the DataFrame

KarlTjensvoll commented 6 years ago

When you create the dataset for X and y, X is created as a pandas DataFrame, since it has more than one column, and y is created as a numpy array, since it has only one column. For DataFrame you need to use the df.iloc[number] if you want it to run through a loop of numbers.