需要以下查询的帮助

时间:2019-04-07 16:20:56

标签: pandas

我收到此错误:

  

标记数据时出错。 C错误:第11行中应有2个字段,看到了3

代码:导入网络浏览器 网站='https://en.wikipedia.org/wiki/Winning_percentage' webbrowser.open(网站)

league_frame = pd.read_clipboard()

接下来是上面提到的

1 个答案:

答案 0 :(得分:1)

我相信您需要使用read_html-返回所有已解析的表并按位置选择Dataframe:

website = 'https://en.wikipedia.org/wiki/Winning_percentage'
#select first parsed table
df1 = pd.read_html(website)[0]
print (df1.head())
  Win %  Wins  Losses  Year                     Team                  Comment
0  0.798    67      17  1882  Chicago White Stockings   best pre-modern season
1  0.763   116      36  1906             Chicago Cubs  best 154-game NL season
2  0.721   111      43  1954        Cleveland Indians  best 154-game AL season
3  0.716   116      46  2001         Seattle Mariners  best 162-game AL season
4  0.667   108      54  1975          Cincinnati Reds  best 162-game NL season

#select second parsed table
df2 = pd.read_html(website)[1]
print (df2)
   Win %  Wins  Losses   Season                   Team  \
0  0.890    73       9  2015–16  Golden State Warriors   
1  0.110     9      73  1972–73     Philadelphia 76ers   
2  0.106     7      59  2011–12      Charlotte Bobcats   

                      Comment  
0         best 82 game season  
1        worst 82-game season  
2  worst season statistically