ValueError: labels ['timestamp'] not contained in axis

 ̄綄美尐妖づ 提交于 2019-12-12 05:09:00

问题


I am learning machine learning and I came across this code. I am trying to run the file "Recommender-Systems.py" from the above source. But it throws an error
ValueError: labels ['timestamp'] not contained in axis.
How can it be removed?

Here's a dropbox link of u.data file.


回答1:


Your data is missing the headers so it's being wrongly inferred by the first row.

You need to change a little bit the Recommender-Systems.py and manually inform the headers.

The right header is available in the README file from your data set.

Change your file to something like this:

## Explore the data (line 27)
data = pd.read_table('u.data', header=None)  # header=None avoid getting the columns automatically
data.columns = ['userID', 'itemID',
                'rating', 'timestamp']       # Manually set the columns.
data = data.drop('timestamp', axis=1)        # Continue with regular work.

...

## Load user information (line 75)
users_info = pd.read_table('u.user', sep='|', header=None)
users_info.columns = ['useID', 'age', 'gender',
                      'occupation' 'zipcode']
users_info = users_info.set_index('userID')

...

## Load movie information (line 88)
movies_info = pd.read_table('u.item', sep='|', header=None)
movies_info.columns = ['movieID', 'movie title', 'release date',
                       'video release date', 'IMDb URL', 'unknown',
                       'Action', 'Adventure', 'Animation', "Children's",
                       'Comedy', 'Crime', 'Documentary', 'Drama',
                       'Fantasy', 'Film-Noir', 'Horror', 'Musical',
                       'Mystery', 'Romance', 'Sci-Fi',' Thriller',
                       'War', 'Western']
movies_info = movies_info.set_index('movieID')#.drop(low_count_movies)


This should work (but I'm not sure if I got all the right names for the columns).



来源:https://stackoverflow.com/questions/37763715/valueerror-labels-timestamp-not-contained-in-axis

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!