Home > OS >  Can't read html table with pd.read_html
Can't read html table with pd.read_html

Time:06-19

on this link: enter image description here

I use this code:

import pandas as pd
url="https://www.basketball-reference.com/teams/MIA/2022.html"
pd.read_html(url,match="Shooting")

But it says: ValueError: No tables found matching pattern 'Shooting'.

If I try pd.read_html(url,match="Roster") or pd.read_html(url,match="Totals") it searches for these tables.

CodePudding user response:

Its the second table that you want to read. You can simply do:

import pandas as pd
url="https://www.basketball-reference.com/teams/MIA/2022.html"
pd.read_html(url)[1]

enter image description here

CodePudding user response:

pd.read_html() isn't finding all the table tags. Only 7 are being returned. Roster, Per Game, Totals, Advanced and 3 others. Shooting is not among them so pd.read_html(url,match="Shooting") is going to give you an error.

import pandas as pd
url = 'https://www.basketball-reference.com/teams/MIA/2022.html'
x = pd.read_html(url)
print(len(x)) #7
  • Related