gpt4 book ai didi

python - 'int' 列的 .apply() 方法出现问题

转载 作者:太空宇宙 更新时间:2023-11-03 21:06:57 25 4
gpt4 key购买 nike

此代码在 python 中使用“pandas”库时出现问题:

尝试在“int”列中应用 .apply () 方法。在我做了一个 def 并尝试使用 (if, else);

但我收到以下错误:

TypeError: ("'> =' not supported between instances of 'list' and 'int'", 'occurred at index A View to a Kill')

我尝试将“年份”列从 int64 传递到“Str”。但它给了我几乎相同的错误。

bond = pd.read_csv('jamesbond.csv', index_col = 'Film')
bond.sort_index(inplace = True)
bond.head(3)



def classic_modern(row):
year = [0]

if year >= 1990 :
return 'The movie is modern'
else :
return 'The movie is old one'
bond.apply(classic_modern , axis = 1)

最佳答案

此行初始化一个具有 1 个值的列表 0:

year = [0]

接下来,您将此列表与整数进行比较,从而导致错误:

if year >= 1990:  # if [0] >= 1990

关于python - 'int' 列的 .apply() 方法出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55337293/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com