pandas :没有找到匹配模式“.+"的表格 [英] Pandas: No tables found matching pattern '.+'
本文介绍了 pandas :没有找到匹配模式“.+"的表格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在使用熊猫读取 html 文件的数据时......这是我的代码:
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)
我收到一个 ValueError,显示没有找到匹配模式.+"的表这是错误:
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:\Users\mayank\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pandas\io\html.py", line 1085, in read_html
return _parse(
File "C:\Users\mayank\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pandas\io\html.py", line 915, in _parse
raise retained
File "C:\Users\mayank\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pandas\io\html.py", line 895, in _parse
tables = p.parse_tables()
File "C:\Users\mayank\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pandas\io\html.py", line 213, in parse_tables
tables = self._parse_tables(self._build_doc(), self.match, self.attrs)
File "C:\Users\mayank\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pandas\io\html.py", line 561, in _parse_tables
raise ValueError(f"No tables found matching pattern {repr(match.pattern)}")
ValueError: No tables found matching pattern '.+'
推荐答案
也许有更好的解决方案,但这对我有用 - 将所有 <...>
标签转换为大写 (也许是熊猫中的一个错误?):
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)
打印:
[ # 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]]
这篇关于 pandas :没有找到匹配模式“.+"的表格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文