Home > Software design >  Need help using pandas to covert a url into a dataframe for college basketball data
Need help using pandas to covert a url into a dataframe for college basketball data

Time:02-19

I am trying to get barttorvik.com data into a dataframe. I can scrape with the following code, but I get an error when trying to export the dataframe into excel.

I am assuming the error has to do with the header row on the site's table. I am unsure how to modify the imported data to make it exportable. Any help would be appreciated and thank you in advance.

import pandas as pd
url = 'https://www.barttorvik.com/#'
df = pd.read_html(url)
df.to_excel('/outputdestination', index=False)

This is the error I get after running the code

AttributeError: 'list' object has no attribute 'to_excel'

CodePudding user response:

See https://pandas.pydata.org/docs/reference/api/pandas.read_html.html. It returns a list of Dataframes.

df[0].to_excel('./outputdestination', index=False)
  • Related