我想对pandas系列数据应用带参数的函数:在SO上我找到了两种不同的解决方案:
python pandas: apply a function with arguments to a series
以及
Passing multiple arguments to apply (Python)
它们都依赖于使用 functool.partial
,并且它们都可以很好地运行。 顺便说一下,Pandas的新版本支持多个参数:无论如何,我不明白它是如何工作的。例如:
a=pd.DataFrame({'x':[1,2],'y':[10,20]})
a['x'].apply(lambda x,y: x+y, args=(100))
它会出现以下错误:
TypeError: <lambda>() argument after * must be a sequence, not int