gpt4 book ai didi

python - 值错误: labels ['timestamp' ] not contained in axis

转载 作者:行者123 更新时间:2023-11-30 09:54:12 25 4
gpt4 key购买 nike

我正在学习机器学习,我遇到了这个code 。我正在尝试从上述源运行文件 "Recommender-Systems.py" 。但它抛出一个错误
ValueError:标签['timestamp']不包含在轴中。
如何将其删除?

这是一个保管箱 link u.data 文件。

最佳答案

您的数据缺少标题,因此第一行错误地推断出它。

您需要稍微更改一下 Recommender-Systems.py 并手动通知 header 。

正确的 header 位于数据集中的 README 文件中。

将您的文件更改为如下内容:

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


这应该可行(但我不确定我是否获得了所有正确的列名称)。

关于python - 值错误: labels ['timestamp' ] not contained in axis,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37763715/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com