python - 有没有办法使用 Python 在 Excel 中执行类似 SQL 的 Select 语句?
问题描述
鉴于此 Excel 表: Excel 文件
假设 SQL Select 语句如下所示:
Select Status from sheet where name = "John Doe" and age = 20
并返回与姓名/年龄匹配的行的状态值 Excel 也可以有超过 1 行。
我还添加了一个从 excel 复制粘贴,但它粘贴了一张图片,我不知道如何分享实际的 excel 内容
解决方案
您可以使用DataFrame.query()方法。像下面这样的东西应该可以完成这项工作:
>>> df
Name Age Height Status
0 John Doe 20 180 Not Married
1 Jhonny Dolly 20 170 Married
>>> df.query('Name == "John Doe" and Age == 20')
Name Age Height Status
0 John Doe 20 180 Not Married
>>> df.query('Name == "John Doe" and Age == 20')[['Status']]
Status
0 Not Married
推荐阅读
- reactjs - 如何处理以文本字段为标签的 Radiobutton 的输入
- c++ - 有条件地删除折叠表达式中的函数调用
- android-studio - MainActivity 无法识别布局中的变量
- python - 编写一个程序,读取文本文件的内容并将单词索引返回到 Values 中
- python - 如何在 Django 中将 UTC 转换为 EST
- python - Python 中的线性代数:计算 3x3 矩阵的特征向量
- android - 为什么anchorNode的子节点在ARCore-Location中与相机平行移动?
- google-drive-api - 注册用户后授予对谷歌驱动器的访问权限
- python - 使用 Python 从 firebase 身份验证中提取创建日期和上次登录
- python - 无法从某些 json 内容中抓取不同深度的所有可用 url