Reading HTML file with Python Pandas into dataframe returns invalid literal for int() with base 10

Viewed 181

I am trying to read and extract tables from wikipedia it generally works for most pages but for some reason for this link it doesn't work: https://en.wikipedia.org/wiki/Great_Britain_at_the_Olympics'

My code is:

import pandas as pd
ukolympics=pd.read_html('https://en.wikipedia.org/wiki/Great_Britain_at_the_Olympics')

Output:

ValueError: invalid literal for int() with base 10: '6;'

I am expecting a list of all tables on the page but I am getting the following error instead and I can't find the way to process the data to avoid trying to convert to int() as it's done by Pandas automatically

1 Answers

I think I have found the problem in wikipedia HTML file, there is an unexpected character after colspan parameter (shown below in screenshot). By editing the table and deleting ; symbol I was able to read the table using pandas.

enter image description here

Please see the link which shows the edit:

Link for the Wiki edit HTML

I am interested in knowing more general solution as often it's impossible to change the table parameters.

Related