无法获得正确的元组格式元组以传递到 Python 中的循环迭代中



我想将参数传递给 API 并获取结果

示例数据

df_results.Unique_Coords
0   51.213:4.386
1   41.294:36.342
2   -7.203:112.733

帕玛特应该是格式

参数格式(预期格式(

(('coords', '44.164:28.641'),
('fromDate', '2019-12-03'),
('toDate', '2019-11-26'))

响应

response = requests.post('https://example.com/geocoder/geocode', headers=headers, params=d_, ,timeout=(3.05, 27))

我正在尝试将值以迭代方式传递到 API 中。

fromDate = today_date

toDate =shifted_date

到目前为止我的代码

today_date =date.today().strftime("%Y-%m-%d")
shifted_date = date.today() + timedelta(days=7)
shifted_date =shifted_date.strftime("%Y-%m-%d")
for i, row in df_results.iterrows():
d_ = '( 'coords' , '{0}' )'.format(str(row["Unique_Coords"]))

如何获得正确的格式?

看起来您正在寻找元组的元组,而不是带有()的字符串

today_date = date.today().strftime("%Y-%m-%d")
shifted_date = date.today() + timedelta(days=7)
shifted_date = shifted_date.strftime("%Y-%m-%d")
data = [(('coords', str(row["Unique_Coords"])), ('fromDate', today_date), ('toDate', shifted_date)) for i, row in df_results.iterrows()]

这将生成元组的元组列表

(('coords', '51.213:4.386'), ('fromDate', '2019-11-26'), ('toDate', '2019-12-03'))
(('coords', '41.294:36.342'), ('fromDate', '2019-11-26'), ('toDate', '2019-12-03'))
(('coords', '-7.203:112.733'), ('fromDate', '2019-11-26'), ('toDate', '2019-12-03'))

最新更新