我有一个pandas数据框“df”,有两列“a”和“B”,有一个函数有两个参数
def myfunction(B, A):
# do something here to get the result
return result
我想使用“apply”函数将它逐行应用到df
df['C'] = df['B'].apply(myfunction, args=(df['A'],))
但我明白了
ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
这里发生了什么事,似乎把df['A]作为整个系列!不仅仅是那个序列中需要的行条目。
我认为你需要:
或:
相关问题 更多 >
编程相关推荐