方法一:把 df.apply(function, axis=1)改为:zip(*df.apply(function, axis=1))
方法二:修改apply循环的那个函数,使其在传入的series中修改,并返回一个series
方法三:在apply中加一个参数result_type,改为:df.apply(add_one, axis=1, result_type=‘expand’)
解决pandas apply返回多个值时报错:ValueError: too many values to unpack
最新推荐文章于 2024-01-20 08:15:00 发布
本文介绍了三种提升Pandas DataFrame中apply方法性能的策略:通过zip转换、直接在函数中修改并返回Series,以及利用result_type参数。这些技巧能有效减少计算时间和内存消耗,提高数据处理效率。
摘要由CSDN通过智能技术生成