如何在稀疏数据帧上使用带有args的pandas.apply?

时间:2018-01-10 23:30:16

标签: python pandas

考虑以下示例:

def sum(row,c,d):
    return row['A']+row['B']+c+d

df = pd.DataFrame(np.random.randint(0,100,size=(10, 2)), columns=list('AB'))

以下按预期运行:

>>> df.apply(sum,axis=1,args=(9,3))
0     59
1    132
2    138
3    129
4    115
5    113
6     99
7     81
8     80
9    189

但转换为稀疏数据帧会导致TypeError:

>>> df.to_sparse().apply(sum,axis=1,args=(9,3))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: apply() got an unexpected keyword argument 'args'

我没有在文档中看到有关针对稀疏数据帧和密集数据帧处理不同的apply()的问题。这是一个错误,还是我误解了什么?

0 个答案:

没有答案