当前位置:网站首页>ValueError: The truth value of a DataFrame is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or
ValueError: The truth value of a DataFrame is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or
2022-07-22 02:05:00 【集电极】
ValueError: The truth value of a DataFrame is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().异常解决方法
我遇到的情况是使用
if
判断了可能是 pd.DataFrame 数据的变量。我需要根据flag
的值决定返回值
错误代码
import pandas as pd
def get_df(flag):
flag = flag # 标志
df = pd.DataFrame() # 模拟数据
if flag:
df = df
else:
df = None
return df
data = get_df(flag=True)
# 错误片段
if data:
print(data)
else:
print(data)
改正
判断
data
的类型是否是pd.DataFrame
再执行下面代码在后面使用过程中,还遇到要判断
pd 数据
是否为空,使用pddata.empty
即可
# 例子 字符串 isinstance(value, str)
if isinstance(data, pd.DataFrame):
print(data)
else:
print(data)
边栏推荐
- 加快标准体系建设,促进数据安全产业高质量发展
- 什么是探索性测试?探索性测试有哪些方法?
- Redis持久化的使用拓展
- Timed time test
- Worthington peptide synthesis application chymotrypsin scheme
- With no performance forecast, BOE is silent at this time?
- 2022-07-13 MySQL query optimization analysis
- Architecture design scheme (continuously updating ing)
- A simple inventory management system source code
- Introduction to microservices
猜你喜欢
Worthington肽合成应用丨胰凝乳蛋白酶方案
2022-07-18 Jenkins deployment
涂鸦Wi-Fi&BLE SoC开发幻彩灯带(5)----烧录授权
你可知道“开源女王”是谁吗?--她面临被解雇的威胁,仍然坚持开源了某个著名项目
Worthington peptide synthesis application chymotrypsin scheme
LVGL之事件处理篇
How to use first-hand data visualization to win the favor of the boss and grasp the key points of data visualization
1. Openpyxl open workbook
A Recommendation for interface-based programming
等保合规2022系列 | 20余年来,等级保护在如何“与时俱进”?
随机推荐
让安全动起来 | 甭管什么行业网络架构,这六招拿下靶标
AIDL示例
商业智能BI分析思维:生产制造行业的现金周期(二)
Introduction to microservices
JVM (一) --------- JVM 简介
Shardingjdbc horizontal split table configuration
2022-07-15 MySQL receives new connection processing
ClickHouse相关SQL总结:创建表、分区/主键/排序设置、删除表、删除分区、修改表字段
Event handling of lvgl
MySQL Exercise one database Knowledge
NFC Introduction (2)
Analysis sample of a video app
【华为机试真题】组成最大数【2022 Q3 | 100分】
分布式链路追踪-skywalking基础
harbor+trivy的安装使用——筑梦之路
Visual studio pit record
2022-07-17 flex/yacc syntax exercise for MySQL
Pdf to image and content reading
Conf configuration of redis
Record online double write failure log MySQL error troubleshooting reasons