ValueError:轴中不包含标签['timestamp'] [英] ValueError: labels ['timestamp'] not contained in axis

查看:243
本文介绍了ValueError:轴中不包含标签['timestamp']的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在学习机器学习,并且遇到了代码. 我正在尝试从上述源运行文件"Recommender-Systems.py".但这会引发错误
ValueError: labels ['timestamp'] not contained in axis.
如何将其删除?

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?

这是u.data文件的保管箱链接.

推荐答案

您的数据缺少标头,因此第一行错误地推断了该数据.

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

您需要稍微更改Recommender-Systems.py并手动通知标题.

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

数据集的README文件中提供了正确的标题.

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).

这篇关于ValueError:轴中不包含标签['timestamp']的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆