带“int”列的.apply()方法有问题

2024-04-25 22:39:44 发布

您现在位置:Python中文网/ 问答频道 /正文

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

正在尝试在“int”列中应用.apply()方法。 在我制作def并尝试使用(if,else)之前

但我得到以下错误:

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

我试图将'Year'列从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)

Tags: csvtheindexreturnifdef错误movie