best way to combine tables when webscraping

Viewed 23

dfs = [] for year in years: with open('team/{}.html'.format(year)) as f: page = f.read()

team['Team'] = team['Eastern Conference'] 
soup = BeautifulSoup(page, 'html.parser')
soup.find('tr', class_='thead').decompose()
team_table = soup.find(id='div_standings_E')
team = pd.read_html(str(player_table))[0]
team['Year'] = year   


dfs.append(team)

team['Team'] = team['Western Conference']
soup = BeautifulSoup(page, 'html.parser')
soup.find('tr', class_='thead').decompose()
team_table = soup.find(id='div_standings_W')
team = pd.read_html(str(player_table))[0]
team['Year'] = year   

These are the two tables:

enter image description here

the error I receive is KeyError: 'Eastern Conference'

0 Answers
Related