如何使用Python和Pandas解析HTML关联矩阵?

如何使用Python和Pandas解析HTML关联矩阵?,python,pandas,beautifulsoup,Python,Pandas,Beautifulsoup,我已经访问了表并将信息引入python,但是我无法迭代列名和行名,以使用正确的相关性值填充表。如何迭代第一行以提取第th列标题值 ctx = ssl.create_default_context() ctx.check_hostname = False ctx.verify_mode = ssl.CERT_NONE req = Request('https://www.mrci.com/special/corr030.php',headers={'User-Agent': 'Mozilla/5

我已经访问了表并将信息引入python,但是我无法迭代列名和行名,以使用正确的相关性值填充表。如何迭代第一行以提取第th列标题值

ctx = ssl.create_default_context()
ctx.check_hostname = False
ctx.verify_mode = ssl.CERT_NONE

req = Request('https://www.mrci.com/special/corr030.php',headers={'User-Agent': 'Mozilla/5.0'})
webpage = urlopen(req, context = ctx).read()

soup = BeautifulSoup(webpage, 'lxml') # Parse the HTML as a string
table = soup.find_all('table')[2] # Grab the first table
for row in table.find_all('tr')[1:]:
    print(row)

有人对我如何将整个表拉入数据框有什么见解吗

您没有显示理想的结果,因此据我猜测,代码可能会对您有所帮助

for row in table.find_all('tr')[1:]:
    for i in row.descendants:
        print(i)
可能重复的