简体   繁体   English

TypeError:列表索引必须是整数或切片,而不是代码的 str

[英]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 rating vote_average -- 评级的列名
dataset -- list containing the details of the movie数据集——包含电影细节的列表
rate_low -- lower range of rating rate_low -- 较低的评级范围
rate_high -- higher range of rating rate_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 values 8 和 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.

相关问题 “TypeError:list indices必须是整数或切片,而不是str” - “TypeError: list indices must be integers or slices, not str” TypeError:列表索引必须是整数或切片,而不是 str - TypeError: List indices must be integers or slices and not str 类型错误:列表索引必须是整数或切片,而不是 str - TypeError: list indices must be integers or slices, not str “TypeError:列表索引必须是整数或切片,而不是 str” - "TypeError: list indices must be integers or slices, not str" TypeError:列表索引必须是整数或切片而不是 str - TypeError: list indices must be integers or slices not str 类型错误:列表索引必须是整数或切片,而不是 str - TypeError: list indices must be integers or slices, not str Python3-TypeError:列表索引必须是整数或切片,而不是str-List - Python3 - TypeError: list indices must be integers or slices, not str - List 使用 Python TypeError 解析 JSON:列表索引必须是整数或切片,而不是 str - Parsing JSON with Python TypeError: list indices must be integers or slices, not str 如何解决“类型错误:列表索引必须是整数或切片,而不是 str” - How to solve "TypeError: list indices must be integers or slices, not str" Scrapy TypeError:列表索引必须是整数或切片,而不是 str - Scrapy TypeError: list indices must be integers or slices, not str
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM