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

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

我正在学习机器学习并且遇到了这个 code。 我正在尝试 运行 来自上述来源的文件 "Recommender-Systems.py"。但它会抛出一个错误
ValueError: labels ['timestamp'] not contained in axis.
如何删除?

这是 u.data 文件的保管箱 link

您的数据缺少 header,因此第一行对其进行了错误推断。

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

您的数据集的 README 文件中提供了正确的 header。

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

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


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