In python 3. with the library pandas, When using the fallowing code
def check_question(df):
mylambda = lambda x: x if x==x else x
return df.apply(mylambda)
print(check_question(df))
The console gave the fallowing ValueError:
ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all()
After several tries the fallowing code fixed it:
def check_question(df):
mylambda = lambda x: x if [x==x] else x
return df.apply(mylambda)
print(check_question(df))
I known, it is something to do with the pandas library: Stackoverflow: The truth value of a Series is ambiguous
I realize that when encapsulation between [], the expression x==x value changes from an ambiguous-thuth-value to a truth-value. I have a vague idea of what it means, but if someone can enlight me more about it, it will greatly appreciated.