5/16/2023 0 Comments Corona tracker in indiaThe outbreak of coronavirus infection soon spread to other provinces of the country, forcing the govt to lockdown dozen of cities with millions of people. Later, its root was traced to a novel strain of coronavirus. ![]() Web Scraping - url = '' # make a GET request to fetch the raw HTML content web_content = requests.get(url).content # parse the html content soup = BeautifulSoup(web_content, "html.parser") # remove any newlines and extra spaces from left and right extract_contents = lambda row: # find all table rows and data cells within stats = all_rows = soup.find_all('tr') for row in all_rows: stat = extract_contents(row.find_all('td')) # notice that the data that we require is now a list of length 5 if len(stat) = 5: stats.append(stat) #now convert the data into a pandas dataframe for further processing new_cols = state_data = pd.DataFrame(data = stats, columns = new_cols) state_data.The first case of coronavirus was reported in December 2019 in the Wuhan city of China as a pneumonia outbreak. Import necessary libraries - import pandas as pd import seaborn as sns import matplotlib.pyplot as plt import requests from bs4 import BeautifulSoup import geopandas as gpd from prettytable import PrettyTable If you are new to web scraping, check this blog for the step-by-step explanation that can help you get started with web scarping using Python. or use this tabulated data to make visualizations using Seaborn/Matplotlib libraries. ![]() Output data in any file format such as csv, xlsx, json, etc.Fetching and parsing the data using Beautifulsoup library and maintain the data in some data structure such as Dictionary or List.Also, identifying your HTML tags where your content lives. Analyzing the HTML tags and their attributes, such as class, id, and other HTML tag attributes.We can do this by using the Request library of Python. Sending an HTTP GET request to the URL of the webpage that you want to scrape, which will respond with the HTML content.To scrape a website using Python, you need to perform these four basic steps: (Note that Geopandas further depends on fiona for file access and descartes and matplotlib for plotting) Scrape the Data If you don’t have any of the above mentioned packages installed on your system, please follow the installation instructions that are mentioned in the respective links. and other regular packages like Pandas, Matplotlib and Seaborn.PrettyTable - quick and easy to represent tabular data in visually appealing ASCII tables.GeoPandas - A library for working with geospatial data in python.Requests - A library for making HTTP requests in python.Beautifulsoup - A library for pulling data out of html and xml files. ![]() I decided to utilize the surplus time to write a Python Script that pulls the latest Statewise data of COVID-19 cases from the official website of Ministry of Health and Family Welfare, Government of India and turn it into insightful visualizations using popular Python packages like GeoPandas, Seaborn and Matplotlib. Plenty has been written about it, especially statistical reports on its exponential growth and the importance of “ flattening the curve ”.Īs of now, most of us are staying and working from home to avoid the spread of corona virus. It has already been declared as a pandemic by WHO and in past couple of weeks it’s impact has been deleterious from both health perspective and an economic one. Coronavirus or COVID-19 needs no introduction.
0 Comments
Leave a Reply. |