[英]Looping through parameters from the mapping table (PYTHON, DATA FRAME)
我有下表,我将其作为 pandas.dataframe 插入:
A B
1 4
1 5
2 4
3 7
3 8
我想在 SQL 中创建 function ,这将 go 通过列 'A' 的特定值,而不是从列 A 和 B 的组合中搜索所有可能的值的数据集。
SQL 脚本如下:
select
cust_id as customer_id,
cust_country_cd as customer_country,
income,
month,
year
from database1
where
cust_id = '{values from column A}',
cust_country_cd = '{values from column B}'
我怎么能用for循环来做呢?
你可以试试这段代码:
for i = 1 To range(df.shape[0])
strQuery = """ select
cust_id as customer_id,
cust_country_cd as customer_country,
income,
month,
year
from database1
where
cust_id = '"""+ df.iloc[i]['A']+"""'
AND cust_country_cd = '"""+ df.iloc[i]['B'] +"""'"""
然后您必须执行查询并获取和构建结果。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.