0

Im trying to scrape this website for nfl standings: https://www.espn.com/nfl/standings

My end goal is to combine the red and the blue part in the picture.

for the red part: I'm trying to make a list of tables for each of the afc's:

import pandas as pd
from bs4 import BeautifulSoup
import requests

url = 'https://www.espn.com/nfl/standings'
result = requests.get(url)
soup = BeautifulSoup(result.text, 'html.parser')
names_table = soup.find_all('table', {'class':'Table Table--align-right Table--fixed Table--fixed-left'})
names_database = pd.read_html(str(names_table[0]))[0]
database = pd.read_html(str(names_table[1]))[0]
names_database.index += 1

list_of_names = []
for i in range(5,len(names_database)+1,5):
    list_of_names.append(names_database.iloc[i-5:i])

for i in list_of_names:
    print(i)

print('\nColumns in table = ', list_of_names[0].columns)

My output:

                        0
1                AFC East
2    x --BUFBuffalo Bills
3       MIAMiami Dolphins
4  NENew England Patriots
5        NYJNew York Jets
                            0
6                   AFC North
7   x --CINCincinnati Bengals
8         BALBaltimore Ravens
9         CLECleveland Browns
10     PITPittsburgh Steelers
                            0
11                  AFC South
12        TENTennessee Titans
13    JAXJacksonville Jaguars
14  e --INDIndianapolis Colts
15      e --HOUHouston Texans
                           0
16                  AFC West
17  z --KCKansas City Chiefs
18   LACLos Angeles Chargers
19       LVLas Vegas Raiders
20     e --DENDenver Broncos

Columns in table =  Int64Index([0], dtype='int64')

I would like to remove the zero on top of each table and replace it with the first column. The afc columns.

I have tried the replace function. with the columns specified as 0 and '0' however it did not work

wjandrea
  • 28,235
  • 9
  • 60
  • 81

0 Answers0