目的:批量处理天池比赛后多个模型数据融合,去除tuijian中的[]问题
以下操作出现:AttributeError: 'float' object has no attribute 'replace'错误
但是探索发现我的列表里面数据本身为str,无float类型
虽然具体float类型指代对象没有找出来(如果哪位朋友知道,希望能提点以下 )
但是加上强制转换以下两种方法可以解决
方法1.
test_usercf_item=pd.DataFrame(test_usercf_item['tuijian'].astype(str))
test_usercf_item['qingxi'] = test_usercf_item.tuijian.apply(lambda x: (x.replace('[]','')))
方法2.
test_usercf_item['qingxi'] = test_usercf_item.tuijian.astype(str ).apply(lambda x: (x.replace('[]','')))