Web Scraping with Pandas | Scraping Tables in 2 minutes!

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello and welcome to this short video in this video we are going to learn how to scrape tables from websites using pandas so I am on this page of Wikipedia list of national capitals and you can see that we have one table here and one table here with a list of countries cities and some notes Here so and there is also another example here how do I get this table and exported to a CSV file well I can use I can import pandas as PD this is an alias and shift enter I'm on my collab and now I can save the URL of that uh web page but you can just copy this and paste it in here and then I can use a method in front pandas use it variable tables I'm going to say within tables and use pdforpanders.read underscore HTML which gives me access to those tables and I pass in the URL here and shift enter or you can just run it now if I take a look at the length of these tables let's see how many tables do we have and you can see we have two tables one is the first table so we can see tables index 0 that is the first table and we can see that here we have list of capitals in alphabetical order so this is it actually this is the one we have so we want the second one which is this so I can say tables index one and you can see this is what we're looking for so I can save this inside a data frame which is like pandas table so we say DF equals tables index of one now it is safe there so I can see the first the F dot had the first five rows by this method and you can see we have it here everything looks good and I can export it now to a CSV my df.2 underscore CSV give it a name like capitals dot CSV capital.csv and let's run this and now we can see it appears here you can download it or you can just view it here as well and you can see this is like so so we have a city and we have the country and some notes here as well so that is it in less than three minutes we scrape tables from a website thank you very much for watching and listening
Info
Channel: Pythonology
Views: 13,644
Rating: undefined out of 5
Keywords: pandas read_html(), pandas web scraping, webscraping pandas, webscraping python, scraping tables
Id: q0EgxM2iAII
Channel Id: undefined
Length: 2min 56sec (176 seconds)
Published: Thu Nov 17 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.