Priyanka Jadhav
Priyanka Jadhav

Reputation: 1

Need assistance with below query

I'm getting this error:

Error tokenizing data. C error: Expected 2 fields in line 11, saw 3

Code: import webbrowser website = 'https://en.wikipedia.org/wiki/Winning_percentage' webbrowser.open(website)

league_frame = pd.read_clipboard()

And the above mentioned comes next.

Upvotes: 0

Views: 40

Answers (1)

jezrael
jezrael

Reputation: 862571

I believe you need use read_html - returned all parsed tables and select Dataframe by position:

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  

Upvotes: 1

Related Questions