Dataframe.isin() giving this error: The truth value of a DataFrame is ambiguous
您能帮助解决这个错误吗:df.isin函数有什么问题?
1 2 3 4 5 6 7 8 | cursor = con.cursor() cursor.execute("""SELECT distinct date FROM raw_finmis_online_activation_temp""") existing_dates = [x[0] for x in cursor.fetchall()] if df[df['date'].isin(existing_dates)]: print"Yes it's in there" else: print"N" |
它给了我这个错误:
ValueError: The truth value of a DataFrame is ambiguous. Use a.empty,
a.bool(), a.item(), a.any() or a.all().
解决方案取决于你想从表达式中得到什么…例如,如果要检查是否至少有一个元素:
1 | len(df[df['date'].isin(existing_dates)]) |
或者如果你想检查所有的元素是否都是"真实的":
1 | df[df['date'].isin(existing_dates)].all() |