为了账号安全,请及时绑定邮箱和手机立即绑定

将 result_type 与 pandas apply 函数一起使用

将 result_type 与 pandas apply 函数一起使用

守着一只汪 2021-07-13 16:13:06
我想在我创建的pandas.DataFrame上使用apply,并为每一行返回一个值列表,其中每个值本身就是一列。我写了以下代码:import pandas as pddef get_list(row):  return [i for i in range(5)]df = pd.DataFrame(0, index=np.arange(100), columns=['col'])df.apply(lambda row: get_list(row), axis=1, result_type='expand')当我添加result_type='expand'以将返回的数组更改为单独的列时,出现以下错误:TypeError: ("<lambda>() got an unexpected keyword argument 'result_type'", 'occurred at index 0')但是,如果我删除result_type它运行良好的字段(返回一列数组),可能是什么问题?我正在使用colab来运行我的代码
查看完整描述

1 回答

  • 1 回答
  • 0 关注
  • 377 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信