covid 19 tracker using python

Solutions on MaxInterview for covid 19 tracker using python by the best coders in the world

showing results for - "covid 19 tracker using python"
Juan Diego
24 Oct 2020
1import pandas as pd
2import seaborn as sns
3import matplotlib.pyplot as plt
4import requests
5from bs4 import BeautifulSoup
6import geopandas as gpd
7from prettytable
8import PrettyTable
9
10url = 'https://www.mohfw.gov.in/'
11# make a GET request to fetch the raw HTML content
12web_content = requests.get(url).content
13# parse the html content
14soup = BeautifulSoup(web_content, "html.parser")
15# remove any newlines and extra spaces from left and right
16extract_contents = lambda row: [x.text.replace('\n', '') for x in row]
17# find all table rows and data cells within
18stats = [] 
19all_rows = soup.find_all('tr')
20for row in all_rows:
21    stat = extract_contents(row.find_all('td')) 
22# notice that the data that we require is now a list of length 5
23    if len(stat) == 5:
24        stats.append(stat)
25#now convert the data into a pandas dataframe for further processing
26new_cols = ["Sr.No", "States/UT","Confirmed","Recovered","Deceased"]
27state_data = pd.DataFrame(data = stats, columns = new_cols)
28state_data.head()
similar questions
queries leading to this page
covid 19 tracker using python