I'm trying to turn a list of tables on this page into a Pandas DataFrame:
CodePudding user response:
A minimal change to your code: pd.read_html returns a list of dataframes for all tables found on the webpage.
Since there is only one table on your page, data1
is a list of 1 dataframe. This is where the error Must pass 2-d input. shape=(1, 38, 12)
comes from – data1
contains 1 dataframe of shape (38, 12).
You probably want to do just:
data2 = data1[0]
data2.to_csv(...)
(Also, no need to sleep after reading from the webpage)