我正在寻找迭代行的方法,但仅对每 20 或 30 行值应用一些方法 所以像这样:
更新代码
for index, row in df.iterrows(), index=+20:
location= geolocator.reverse("%s, %s" % (row['lat'],row['long']),timeout=None)
row['location']=location.address
time.sleep(3)
return df
实际上我尽量减少请求的数量,否则我会遇到超时问题。这就是为什么我尝试遍历行,并且只对每 20 行或第 60 行应用请求函数(因为我有 7000 行),而不是通过应用 time.sleep 方法来加快进程
最佳答案
试试这个:
for index, row in enumerate(df):
if index % 20 == 0:
# do something
关于python - 遍历行,并控制计数 i++,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33299988/