【问题标题】:Why is the value of i not increasing in the python code below? What should I do to increase it?为什么 i 的值在下面的 python 代码中没有增加?我应该怎么做才能增加它?
【发布时间】:2022-11-20 19:05:25
【问题描述】:

为什么 i 的值在下面的 python 代码中没有增加?我应该怎么做才能增加它?

i = 0
for z in analink2.iloc[i,[1]]:
    req = requests.get(z, headers = header)
    print(z)
    i += 1
analink2.head()
Out[268]: 
             section                                            weblink
0  bilgisayar-tablet  https://www.trendyol.com/bilgisayar-tablet-x-c...
1  bilgisayar-tablet  https://www.trendyol.com/bilgisayar-tablet-x-c...
2  bilgisayar-tablet  https://www.trendyol.com/bilgisayar-tablet-x-c...
3  bilgisayar-tablet  https://www.trendyol.com/bilgisayar-tablet-x-c...
4  bilgisayar-tablet  https://www.trendyol.com/bilgisayar-tablet-x-c...

只要 z 在循环中,我希望 i 的值增加并且 z 的索引随 i 增加

【问题讨论】:

    标签: python dataframe loops for-loop python-requests


    【解决方案1】:

    如果您想遍历 weblink 列中的值,您可以使用下一个示例:

    for url in analink2["weblink"]:
        print(url)
        req = requests.get(url, headers=header)
    

    如果你想要索引值,你可以使用例如.iterrows()

    for idx, row in analink2.iterrows():
        print(idx, row['weblink'])
        req = requests.get(row['weblink'], headers=header)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-11-15
      • 2016-06-19
      • 2018-12-08
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多