2024-10-04 03:17:54 发布
网友
使用python特定列的Web刮表
import pandas as pd url = 'https://www.sharesansar.com/today-share-price' tables = pd.read_html(url) print(tables[1][1])
Pandas模块“read_html(url)”返回网页中所有要刮取的表的列表。在当前页面中('https://www.sharesansar.com/today-share-price)桌子上只有一个。因此,如果您想访问该表,您应该获取列表的第一个索引
import pandas as pd url = 'https://www.sharesansar.com/today-share-price' tables = pd.read_html(url) df = tables[0] firstRow = df.iloc[[0]] firstTwoColumns = df.iloc[: , [0, 1]]
要选择特定的列/行,请使用pandas模块
.iloc
.loc
正在发生的事情:
Pandas模块“read_html(url)”返回网页中所有要刮取的表的列表。在当前页面中('https://www.sharesansar.com/today-share-price)桌子上只有一个。因此,如果您想访问该表,您应该获取列表的第一个索引
解决方案:
要选择特定的列/行,请使用pandas模块
相关问题 更多 >
编程相关推荐