pandas dataframe 报错:ValueError: The truth value of a DataFrame is ambiguous. Use a.empty, a.bool()

发现jenkins任务跑python脚本报错了。报错内容为下文。

ValueError: The truth value of a DataFrame is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all()

代码类似为下文:判断dataframe是否为空,为空则执行if语句内的内容。

df =pd.DataFrame()
if not result:
	print('该dataframe为空。')

像上面那么写,直接报错了。应该是以为dataframe这个类型即使不放数据,它也不算空。
所以pandas不让这么判断。

应该使用empty来判断:

df =pd.DataFrame()
if result.empty:
	print('该dataframe为空。')

猜你喜欢

转载自blog.csdn.net/qq_44821149/article/details/130772147
今日推荐