I have seen that recently table for List of postal codes of Canada on Wikipedia has changed from normal table to common grid style List of postal codes of Canada: M.
I tried in different way but its not easy to convert it into df.
Problem with this data is it is values are not separated by tr tag.I want a df in the old format of data like Old format
My question is - can i do this with bs4 or any python code directly or I have to import table as it is and then modify df. If there is easy way please help me.
My code gives result like this :
import requests
from bs4 import BeautifulSoup
req = requests.get("https://en.wikipedia.org /wiki/List_of_postal_codes_of_Canada:_M")
soup = BeautifulSoup(req.content,'lxml')
table = soup.find_all('table')[0]
print(table.tr.text)
df = pd.read_html(str(table))
df=pd.DataFrame(df[0])