Pandas is refusing to parse a specific Wikipedia page

Viewed 21

I'm trying to work with some data on presidential elections in the US, so I'm using pandas to parse Wikipedia pages containing the results. For some reason, the page for the 2012 election is parsed alright, while trying to parse the page for the 2016 one results in an extremely curious error:

>>> import pandas as pd
>>> df_2012 = pd.read_html("https://en.wikipedia.org/wiki/2012_United_States_presidential_election")
>>> df_2016 = pd.read_html("https://en.wikipedia.org/wiki/2016_United_States_presidential_election")
Traceback (most recent call last):
  File "<pyshell#2>", line 1, in <module>
    df_2016 = pd.read_html("https://en.wikipedia.org/wiki/2016_United_States_presidential_election")
  File "C:\Users\Gleb\AppData\Local\Programs\Python\Python38\lib\site-packages\pandas\util\_decorators.py", line 317, in wrapper
    return func(*args, **kwargs)
  File "C:\Users\Gleb\AppData\Local\Programs\Python\Python38\lib\site-packages\pandas\io\html.py", line 1205, in read_html
    return _parse(
  File "C:\Users\Gleb\AppData\Local\Programs\Python\Python38\lib\site-packages\pandas\io\html.py", line 1009, in _parse
    for table in tables:
  File "C:\Users\Gleb\AppData\Local\Programs\Python\Python38\lib\site-packages\pandas\io\html.py", line 263, in <genexpr>
    return (self._parse_thead_tbody_tfoot(table) for table in tables)
  File "C:\Users\Gleb\AppData\Local\Programs\Python\Python38\lib\site-packages\pandas\io\html.py", line 478, in _parse_thead_tbody_tfoot
    body = self._expand_colspan_rowspan(body_rows, section="body")
  File "C:\Users\Gleb\AppData\Local\Programs\Python\Python38\lib\site-packages\pandas\io\html.py", line 533, in _expand_colspan_rowspan
    rowspan = int(self._attr_getter(td, "rowspan") or 1)
ValueError: invalid literal for int() with base 10: '{{{vp_count}}}'
>>> 

How can I address that bug?

0 Answers
Related