Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
603 views
in Technique[技术] by (71.8m points)

python - Pandas: No tables found matching pattern '.+'

while using pandas to read an html file's data....Here is my code:

import pandas as pd 
import geopandas as gpd
import requests

url=requests.get("https://www.worldometers.info/coronavirus/")
dataframe=pd.read_html(url.text)
print(dataframe)    

i got an ValueError showing No tables found matching pattern '.+' here is the error:

 C:/Users/mayank/AppData/Local/Programs/Python/Python38-32/python.exe e:/skills/mayankvscod
e/projects/coronavirus_worldometer/corona_meter.py
Traceback (most recent call last):
  File "e:/skills/mayankvscode/projects/coronavirus_worldometer/corona_meter.py", line 6, in
<module>
    dataframe=pd.read_html(url.text)
  File "C:UsersmayankAppDataLocalProgramsPythonPython38-32libsite-packagespandasiohtml.py", line 1085, in read_html
    return _parse(
  File "C:UsersmayankAppDataLocalProgramsPythonPython38-32libsite-packagespandasiohtml.py", line 915, in _parse
    raise retained
  File "C:UsersmayankAppDataLocalProgramsPythonPython38-32libsite-packagespandasiohtml.py", line 895, in _parse
    tables = p.parse_tables()
  File "C:UsersmayankAppDataLocalProgramsPythonPython38-32libsite-packagespandasiohtml.py", line 213, in parse_tables
    tables = self._parse_tables(self._build_doc(), self.match, self.attrs)
  File "C:UsersmayankAppDataLocalProgramsPythonPython38-32libsite-packagespandasiohtml.py", line 561, in _parse_tables
    raise ValueError(f"No tables found matching pattern {repr(match.pattern)}")
ValueError: No tables found matching pattern '.+'
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Maybe there's better solutions, but this is what worked for me - convert all <...> tags to uppercase (maybe a bug in pandas?):

import re
import requests

html_source = requests.get("https://www.worldometers.info/coronavirus/").text
html_source = re.sub(r'<.*?>', lambda g: g.group(0).upper(), html_source)

dataframe=pd.read_html(html_source)
print(dataframe)

Prints:

[      #  Country,Other  TotalCases NewCases  TotalDeaths NewDeaths  TotalRecovered  ... TotalTests  Tests/ 1M pop  Population          Continent  1 Caseevery X ppl  1 Deathevery X ppl  1 Testevery X ppl
0   NaN  North America     2333333   +5,613     138581.0      +642        966689.0  ...        NaN            NaN         NaN      North America                NaN                 NaN                NaN
1   NaN  South America     1219723     +695      52857.0       +12        563854.0  ...        NaN            NaN         NaN      South America                NaN                 NaN                NaN
2   NaN         Europe     2134390   +9,695     180463.0      +279       1117440.0  ...        NaN            NaN         NaN             Europe                NaN                 NaN                NaN
3   NaN           Asia     1440771  +16,501      36529.0      +232        871289.0  ...        NaN            NaN         NaN               Asia                NaN                 NaN                NaN
4   NaN         Africa      206520   +1,000       5578.0       +10         93197.0  ...        NaN            NaN         NaN             Africa                NaN                 NaN                NaN
..   ..            ...         ...      ...          ...       ...             ...  ...        ...            ...         ...                ...                ...                 ...                ...
226 NaN         Total:     1440771  +16,501      36529.0      +232        871289.0  ...        NaN            NaN         NaN               Asia                NaN                 NaN                NaN
227 NaN         Total:      206520   +1,000       5578.0       +10         93197.0  ...        NaN            NaN         NaN             Africa                NaN                 NaN                NaN
228 NaN         Total:        8887       +9        124.0       NaN          8332.0  ...        NaN            NaN         NaN  Australia/Oceania                NaN                 NaN                NaN
229 NaN         Total:         721      NaN         15.0       NaN           651.0  ...        NaN            NaN         NaN                NaN                NaN                 NaN                NaN
230 NaN         Total:     7344345  +33,513     414147.0    +1,175       3621452.0  ...        NaN            NaN         NaN                All                NaN                 NaN                NaN

[231 rows x 19 columns],       #  Country,Other  TotalCases  NewCases  TotalDeaths NewDeaths  TotalRecovered  ... TotalTests  Tests/ 1M pop  Population          Continent  1 Caseevery X ppl  1 Deathevery X ppl  1 Testevery X ppl
0   NaN           Asia     1424270   +31,788      36297.0      +658        864232.0  ...        NaN            NaN         NaN               Asia                NaN                 NaN                NaN
1   NaN  North America     2327720   +24,384     137939.0    +1,554        963408.0  ...        NaN            NaN         NaN      North America                NaN                 NaN                NaN
2   NaN  South America     1219028   +42,752      52845.0    +1,518        563823.0  ...        NaN            NaN         NaN      South America                NaN                 NaN                NaN
3   NaN         Europe     2124695   +14,928     180184.0      +824       1105422.0  ...        NaN            NaN         NaN             Europe                NaN                 NaN                NaN
4   NaN         Africa      205520    +6,530       5568.0      +178         92914.0  ...        NaN            NaN         NaN             Africa                NaN                 NaN                NaN
..   ..            ...         ...       ...          ...       ...             ...  ...        ...            ...         ...                ...                ...                 ...                ...
226 NaN         Total:     2124695   +14,928     180184.0      +824       1105422.0  ...        NaN            NaN         NaN             Europe                NaN                 NaN                NaN
227 NaN         Total:      205520    +6,530       5568.0      +178         92914.0  ...        NaN            NaN         NaN             Africa                NaN                 NaN                NaN
228 NaN         Total:        8878        +3        124.0       NaN          8308.0  ...        NaN            NaN         NaN  Australia/Oceania                NaN                 NaN                NaN
229 NaN         Total:         721       NaN         15.0       NaN           651.0  ...        NaN            NaN         NaN                NaN                NaN                 NaN                NaN
230 NaN         Total:     7310832  +120,385     412972.0    +4,732       3598758.0  ...        NaN            NaN         NaN                All                NaN                 NaN                NaN

[231 rows x 19 columns],       #  Country,Other  TotalCases  NewCases  TotalDeaths NewDeaths  TotalRecovered  ... TotalTests  Tests/ 1M pop  Population          Continent  1 Caseevery X ppl  1 Deathevery X ppl  1 Testevery X ppl
0   NaN           Asia     1392482   +31,253      35639.0      +614        842914.0  ...        NaN            NaN         NaN               Asia                NaN                 NaN                NaN
1   NaN  North America     2303336   +24,856     136385.0      +848        943277.0  ...        NaN            NaN         NaN      North America                NaN                 NaN                NaN
2   NaN  South America     1176276   +29,806      51327.0    +1,105        559961.0  ...        NaN            NaN         NaN      South America                NaN                 NaN                NaN
3   NaN         Europe     2109767   +14,920     179360.0      +417       1088915.0  ...        NaN            NaN         NaN             Europe                NaN                 NaN                NaN
4   NaN         Africa      198990    +6,872       5390.0      +173         88212.0  ...        NaN            NaN         NaN             Africa                NaN                 NaN                NaN
..   ..            ...         ...       ...          ...       ...             ...  ...        ...            ...         ...                ...                ...                 ...                ...
226 NaN         Total:     2109767   +14,920     179360.0      +417       1088915.0  ...        NaN            NaN         NaN             Europe                NaN                 NaN                NaN
227 NaN         Total:      198990    +6,872       5390.0      +173         88212.0  ...        NaN            NaN         NaN             Africa                NaN                 NaN                NaN
228 NaN         Total:        8875        +5        124.0       NaN          8294.0  ...        NaN            NaN         NaN  Australia/Oceania                NaN                 NaN                NaN
229 NaN         Total:         721       NaN         15.0       NaN           651.0  ...        NaN            NaN         NaN                NaN                NaN                 NaN                NaN
230 NaN         Total:     7190447  +107,712     408240.0    +3,157       3532224.0  ...        NaN            NaN         NaN                All                NaN                 NaN                NaN

[231 rows x 19 columns]]

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...