我得到了这个错误。TypeError:必须是str,而不是float

2024-04-25 02:20:25 发布

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

from ast import literal_eval

功能=['cast'、'crew'、'keywords'、'tyres'] 对于要素中的要素: df1[feature]=df1[feature]。应用(文字值)

def get_控制器(x): 对于x中的i: 如果我['job']=='Director': 返回i['name'] 返回np.nan def get_列表(x): 如果isinstance(x,列表): 名称=[i['name']表示x中的i] #检查是否存在3个以上的元素。如果是,只返回前三个。如果否,返回整个列表。 如果len(名称)>;三: 名称=名称[:3] 返回名称

#Return empty list in case of missing/malformed data
return []

df1['director']=df1['crew'].申请(获得董事)

功能=['cast','keywords','genres'] 对于要素中的要素: df1[feature]=df1[feature]。应用(获取列表)

def清洁_数据(x): 如果isinstance(x,列表): 返回[str.lower(i.replace(“,”)表示x中的i] 其他: #检查是否存在控制器。如果不是,则返回空字符串 如果存在(x,str): 返回str.lower(x.replace(“,”)) 其他: 返回“”

def创建_汤(x): 返回“”。加入(x['keywords'])+“”+“”。加入(x['cast'])+“”+x['director']+“”。加入(x['genres'])) df1['soup']=df1.apply(创建\u soup,axis=1)

当我试图执行我的创建汤时,它给出了一个错误“TypeError:必须是str,而不是float”请协助


Tags: name功能名称列表getdef控制器feature