Digitei:
import requests
from bs4 import BeautifulSoup
import pandas as pd
url='https://www.federalreserve.gov/releases/h3/current/default.htm'
response = requests.get(url)
html = response.content
soup = BeautifulSoup(html, 'html.parser')
table = soup.findAll('table')
html_file = f'<html><body>{table}</body></html>'
df = pd.read_html(html_file)
# Como a função read_html retorna uma lista de DataFrames, basta acessar as tabelas pelos índices da lista.
# Como temos três tabelas na página usamos os índices 0, 1 ou 2 para acessar os DataFrames que buscamos
df[0]
Mas resulta sempre em:
ImportError Traceback (most recent call last)
Input In [23], in <cell line: 11>()
9 table = soup.findAll('table')
10 html_file = f'<html><body>{table}</body></html>'
---> 11 df = pd.read_html(html_file)
13 # Como a função read_html retorna uma lista de DataFrames, basta acessar as tabelas pelos índices da lista.
14 # Como temos três tabelas na página usamos os índices 0, 1 ou 2 para acessar os DataFrames que buscamos
15 df[0]
File ~\anaconda3\envs\alura_pandas\lib\site-packages\pandas\util\_decorators.py:311, in deprecate_nonkeyword_arguments.<locals>.decorate.<locals>.wrapper(*args, **kwargs)
305 if len(args) > num_allow_args:
306 warnings.warn(
307 msg.format(arguments=arguments),
308 FutureWarning,
309 stacklevel=stacklevel,
310 )
--> 311 return func(*args, **kwargs)
File ~\anaconda3\envs\alura_pandas\lib\site-packages\pandas\io\html.py:1113, in read_html(io, match, flavor, header, index_col, skiprows, attrs, parse_dates, thousands, encoding, decimal, converters, na_values, keep_default_na, displayed_only)
1109 validate_header_arg(header)
1111 io = stringify_path(io)
-> 1113 return _parse(
1114 flavor=flavor,
1115 io=io,
1116 match=match,
1117 header=header,
1118 index_col=index_col,
1119 skiprows=skiprows,
1120 parse_dates=parse_dates,
1121 thousands=thousands,
1122 attrs=attrs,
1123 encoding=encoding,
1124 decimal=decimal,
1125 converters=converters,
1126 na_values=na_values,
1127 keep_default_na=keep_default_na,
1128 displayed_only=displayed_only,
1129 )
File ~\anaconda3\envs\alura_pandas\lib\site-packages\pandas\io\html.py:915, in _parse(flavor, io, match, attrs, encoding, displayed_only, **kwargs)
913 retained = None
914 for flav in flavor:
--> 915 parser = _parser_dispatch(flav)
916 p = parser(io, compiled_match, attrs, encoding, displayed_only)
918 try:
File ~\anaconda3\envs\alura_pandas\lib\site-packages\pandas\io\html.py:872, in _parser_dispatch(flavor)
870 else:
871 if not _HAS_LXML:
--> 872 raise ImportError("lxml not found, please install it")
873 return _valid_parsers[flavor]
ImportError: lxml not found, please install it
Não estou conseguindo avançar agora. Tentei fazer conda install -c anaconda lxml
ou conda install -c anaconda xlrd
no ambiente virtual do Prompt de comando, tentei !pip install lxml
no Jupyter Notebook, mas está resultando no ImportError acima sempre.