python - Panda.run_sql_query for where .. in .. 结构?
问题描述
我有一个结构为 where a in b kind 的 sql 查询。我正在尝试使用 run_sql_query 通过 pandas 运行它以获取数据帧。但似乎没有数据结构适用于熊猫查询。我应该有什么让它工作?
sql:
Select * from Table where a in (:input)
Python:
conn = cx-oracle.connect(....)
df = pd.run_sql_query(sql,conn, params= {'input':('A','B')})
错误信息:
cx_Oracle.NotSupportedError: Python value of type tuple not supported.
我尝试了 numpy 数组和列表,但似乎没有一个工作。这里应该使用什么数据结构?
解决方案
尝试这个:
myinput = ('a','b','c')
myinput = str(myinput)
#Now your query will end up like
# select * from tablename where value in ('a','b','c')
df = pd.run_sql_query(sql,conn, params= {'input':myinput})
推荐阅读
- android - Linphone 核心监听器未接听来电
- hibernate - @Embeddable 具有复杂字段的复合主键
- android - 如何从自定义样式属性(R.attr.text_color)Android 中设置 TextColor
- jquery - 用户单击特定链接后更改活动选项卡不起作用
- python - 无法从 AWS Cloud9 上的 bs4 导入 BeautifulSoup
- r - 生成具有不同大小的曲线以连接 ggplot2 中的点
- cumulocity - 如何在cumulocity中添加多个微服务
- asp.net-core - bundelconfig.json 在哪里执行?
- python - 需要合并数据框中的两列
- c# - Postsharp AOP 方法拦截方面不起作用