我尝试了一本书中的示例代码。这本书名为“Python for Data Analysis'”。该书说要转到以下链接并下载数据:http://www.grouplens.org/node/73
我做到了。我成功运行了以下脚本。
import pandas as pd
unames = ['user_id', 'gender', 'age', 'occupation', 'zip']
users = pd.read_table('C:\\Users\\Excel\\Desktop\\Briefcase\\PDFs\\Python\\SampleData\\movies.dat', sep='::', header=None, names=unames)
rnames = ['user_id', 'movie_id', 'rating', 'timestamp']
ratings = pd.read_table('C:\\Users\\Excel\\Desktop\\Briefcase\\PDFs\\Python\\SampleData\\movies.dat', sep='::', header=None, names=rnames)
mnames = ['movie_id', 'title', 'genres']
movies = pd.read_table('C:\\Users\\Excel\\Desktop\\Briefcase\\PDFs\\Python\\SampleData\\movies.dat', sep='::', header=None, names=mnames)
data = pd.merge(pd.merge(ratings, users), movies)
一切正常!现在,这本书说试试这个:
mean_ratings = data.pivot_table('rating', rows='title', cols='gender', aggfunc='mean')
该行给了我这个错误:
Traceback (most recent call last):
File "<pyshell#23>", line 1, in <module>
mean_ratings = data.pivot_table('rating', rows='title', cols='gender', aggfunc='mean')
TypeError: pivot_table() got an unexpected keyword argument 'rows'
我不知道这里有什么问题。有人可以帮我解释一下吗? 谢谢!