0
import numpy as np
import pandas
data=pandas.read_table('u.data',names=['user id','item id','rating','timestamp']
user=pandas.read_table('u.user', sep='|',names=['user id ','age','gender','occupation','zip code'])
item=pandas.read_table(r'u.item', sep='|',names=['movie id','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'])
data.sort_values('user id', inplace=True)
Averge=pandas.pivot_table(data, values='rating', columns=['user id'], aggfunc='mean')
M=[]
F=[]
#There is an error
for i in range(944):
if user.iloc[i]['gender']=='M':
M.append(Averge[i+1])
else:
F.append(Averge[i+1])
IndexError: single positional indexer is out-of-bounds
它看起来像你的问题是所有的代码。您需要为您的问题提供上下文,并格式化所有代码块(选择它们,然后按) –
谢谢!我现在尝试。 –