[英]TypeError: list indices must be integers or slices, not str for the code
def rate_bucket(dataset, rate_low, rate_high):
rated_movies = dataset[(dataset['vote_average']>rate_low)&(dataset['vote_average']<=rate_high)]
print(rated_movies)
Keyword arguments:
关键字 arguments:
vote_average -- column name for ratingvote_average -- 评级的列名
dataset -- list containing the details of the movie数据集——包含电影细节的列表
rate_low -- lower range of ratingrate_low -- 较低的评级范围
rate_high -- higher range of ratingrate_high -- 更高的评级范围
Returns rated_movies -- list of the details of the movies with required ratings返回rated_movies -- 具有所需评级的电影的详细信息列表
Function call statement
Function 调用语句
rate_bucket(movies,8,10)
movies is the dataset
电影是数据集
8 and 10 are rating values8 和 10 是额定值
dataset -- list containing the details of the movie
数据集——包含电影细节的列表
You cannot extract values from a list like this:您不能从这样的列表中提取值:
dataset['vote_average']
This will work, only if dataset is a Panda dataframe.只有当数据集是 Panda dataframe 时,这才有效。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.