Skip to content
Advertisement

How to accumulate in a df parsed data through a loop with pandas from a web scrapping?

I want to create a df with an historical dataset by scrapping a website, but I struggle to accumulate the full period within the loop. I am able to download a day, but when I try to create a loop to storage a set of iterations I am not able to accumulate the data in the dataframe.

The df I want to create from the start_date to the end_date is as follows:

Fecha PeríodeTU TM°C HRM%
single_date

Where Fecha is a result of adding a columns with the single_date of the code below, and the rest of the columns are actual data from the website scrapped.

I have tried this:

JavaScript

df_table only saves the last date, and I want to save the full period iterated.

Does anyone know how to deal with this situation?

Advertisement

Answer

You can create a list and the concatenate it:

JavaScript

And finally after running the loop:

JavaScript

This will create df_table with all the individual observations from the dataframes based on your loop.

Advertisement