python 在一行中包含多个参数的 For 循环

For loop with multiple arguments in one line with python

我正在使用 google_streetview.api,但遇到无法解决的问题。文档告诉我可以 运行 在一行中通过用 ; 分隔多个参数。但我不知道如何在一行中循环使用值。我有一个带有循环的 x 和 y 坐标的数据框。标准版本如下所示:

params = [{
'size': '600x300', # max 640x640 pixels
'location': '46.414382,10.013988',
'heading': '151.78',
'pitch': '-0.76',
'key': 'your_dev_key'
}]

我需要这条线:

'location': '1234,1234',

这样走:

for coor, row in df.iterrows():
    x=row.POINT_X
    y=row.POINT_Y
    'location': 'POINT_Y1,POINT_X1; POINT_Y2, POINT_X2; and so on',

我首先对完整参数进行了循环,但是当我使用 ; 跳过分隔时我最终得到了很多单个 json 文件,我需要能够告诉它添加 ;对于数据框中的每个 x 和 y。

';'.join([r.POINT_X + ',' + r.POINT_Y for _, r in df.iterrows()])

当然,您需要指定将 x 和 y 点添加到 params 字典的 location 索引中。

您可能希望根据坐标构建一个列表并将它们连接成一个字符串:

#creates a list of string with the (x, y) coordinates
coords = [','.join([row.POINT_X, row.POINT_Y]) for row in df.iterrows()]
#creates a string out of the coordinates separated by ";"
#and sets it as the value for the location index in params.
params[0]['location'] = ';'.join(coords)

请注意,我假设参数已经存在。