热线电话:13121318867

登录
2019-01-26 阅读量: 683
如何使用Pandas html函数解析表?

我正试图在这里找到表格。使用下面的代码,但它返回多级索引。任何帮助表示赞赏。

url1='aboveurl.htm'

df1=pd.read_html(url1)

df1=df1[0]

df=df[0]

df.columns=df.columns.droplevel()

这将根据喜好删除多索引。

print(df.head())

Rk School Conf W L Pct W L Pct Off \

0 1 Clemson ACC (Atlantic) 12 2 .857 7 1 .875 33.3

1 2 North Carolina State ACC (Atlantic) 9 4 .692 6 2 .750 32.2

2 3 Louisville ACC (Atlantic) 8 5 .615 4 4 .500 38.1

3 4 Wake Forest ACC (Atlantic) 8 5 .615 4 4 .500 35.3

4 5 Boston College ACC (Atlantic) 7 6 .538 4 4 .500 25.7

Def SRS SOS AP Pre AP High AP Rank Notes

0 13.6 20.62 6.84 5 1 4 NaN

1 25.2 12.17 5.55 NaN 14 23 NaN

2 27.4 9.67 3.75 16 14 NaN NaN

3 28.3 11.42 6.03 NaN NaN NaN NaN

4 22.8 9.39 7.08 NaN NaN NaN NaN

0.0000
1
关注作者
收藏
评论(0)

发表评论

暂无数据
推荐帖子