简体   繁体   English

Python Pandas Dataframe - 只有 output 的第一行被保存在行中

[英]Python Pandas Dataframe - Only first line of output gets saved in row

In my webscraper i get URLs from Json Data with a For Loop, then it gets assorted in a dataframe to 'Images' and then written to a csv. However both the dataframe and the csv only save the first line of the output.在我的 webscraper 中,我使用 For 循环从 Json 数据中获取 URL,然后它在 dataframe 中分类为“图像”,然后写入 csv。但是 dataframe 和 csv 都只保存 814498671188 的第一行 8183347

Part of my Code where the for loop is:我的代码的一部分,其中 for 循环是:

images = json_data[3]["options"]["images"]
    for image in images:
        src = (image['url'])

    scraped = {
        'Images': src,
    }
    scrapedresult.append(scraped)

The output while debugging: https://prnt.sc/1ucgxpa (all URLs you see here belong to one row, however, only the first URL gets saved in the row of the dataframe)调试时的 output: https://prnt.sc/1ucgxpa (您在此处看到的所有 URL 都属于一行,但是,只有第一个 URL 保存在数据框的行中)

What can I do so the output gets as a whole into the row of the dataframe?我该怎么做才能将 output 作为一个整体放入 dataframe 的行中?

Place the scrapedresult.append within the scope of the for statement like so.像这样将 scrapedresult.append 放在 for 语句的 scope 中。

images = json_data[3]["options"]["images"] for image in images: src = (image['url']) images = json_data[3]["options"]["images"] 图像中的图像:src = (image['url'])

scraped = {
    'Images': src,
}
    scrapedresult.append(scraped)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM