This code is about web scraping. The problem is when i run this code a get some error whis is "ValueError: Length of passed values is 6, index implies 7 ". How can i fix this error. the values langth is but index length is 7 that's why error occurs.
import requests
from bs4 import BeautifulSoup
import pandas as pd
url="https://en.wikipedia.org/wiki/List_of_Game_of_Thrones_episodes"
page=requests.get(url)
soup=BeautifulSoup(page.text,'html.parser')
table=soup.find('table',{'class':'wikitable plainrowheaders wikiepisodetable'}).tbody
rows=table.find_all('tr')
columns=[v.text.replace('\u200a[20]','') for v in rows[0].find_all('th')]
df=pd.DataFrame(columns=columns)
for record in range(1,len(rows)):
tds=rows[record].find_all('td')
if len(tds)==4:
values=[tds[0].text,tds[1].text,tds[2].text,tds[3].text]
else:
values=[td.text for td in tds]
df=df.append(pd.Series(values,index=columns),ignore_index=True)
print(df)
Hare is the error in line number 25.The error is given below.
File "good.py", line 25, in <module>
df=df.append(pd.Series(values,index=columns),ignore_index=True)
File "C:\Users\User\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pandas\core\series.py", line 300, in __init__
raise ValueError(
ValueError: Length of passed values is 6, index implies 7```
how can i solve this problem:::::