Skip to content Skip to sidebar Skip to footer

Exporting Several Scraped Tables Into A Single Csv File

How can I concatenate the tables read from several HTML? I understand they are considered lists and lists are not possible to concatenate, but then how can I insert more than one t

Solution 1:

pd.read_html returns a list of dataframes. So, in case you are sure that the lists contains dataframes formated in a way that can be concatenated you can consolidate then into a single dataframe, then export it to csv:

import pandas as pd

dframes_list1 = pd.read_html('URL1')
dframes_list2 = pd.read_html('URL2')
dframes_all = dframes_list1 + dframes_list2
consolidated_dframe = pd.concat(dframes_all)
consolidated_dframe.to_csv('name.csv')

Post a Comment for "Exporting Several Scraped Tables Into A Single Csv File"