【问题标题】:iterating in dataframe using python使用python在数据框中迭代
【发布时间】:2016-06-13 23:09:18
【问题描述】:

我需要从 Dataframe 中迭代,其中 str 像

http://work4you.su/register
http://vk.com/anime_yes
http://vk.com/anime_yes?z=photo-33172903_414023351%2Fwall-33172903_34658
http://yandex.ru/search?
http://vk.com/anime_yes?z=photo-33172903_413008739%2Fwall-33172903_34522

如果yandex.ru/searchurl 中打印next url == 'yandex'。我尝试url.next() == 'yandex',但它不起作用

【问题讨论】:

    标签: python loops pandas


    【解决方案1】:

    看起来问题的症结在于在 Dataframe 中查找下一行

    for index,row in enumerate(df[column_with_urls][:-1]):
        if 'yandex.ru/search' in row: print df[column_with_urls][index+1] == 'yandex.ru'
    

    enumerate 允许您遍历行和索引,并且您可以使用索引查找当前行下方第一行的值。

    【讨论】:

    • 它不打印这个值,它返回False这个值
    • 它返回False而不是index + 1,它返回到str,其中包含yandex.ru
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-12-07
    • 1970-01-01
    • 2021-09-18
    • 1970-01-01
    • 2020-09-27
    • 1970-01-01
    • 2022-01-02
    相关资源
    最近更新 更多