Skip to content

Instantly share code, notes, and snippets.

View animationdataload.py
import requests
import pandas
import json
import plotly.express as px
districts_daily = requests.get('https://api.covid19india.org/v4/timeseries.json')
districts_daily = districts_daily.text
districts_daily = json.loads(districts_daily)
dfs = []
View geojsondata.py
active = []
confirmed = []
deaths = []
deltaconfirmed = []
deltadeaths = []
deltarecovered = []
recovered = []
state = []
for data in districts_daily['statewise']:
active.append(data['active'])
View dataloadingline.py
import plotly.graph_objects as go
import requests
import pandas
import json
districts_daily = requests.get('https://api.covid19india.org/data.json')
districts_daily = districts_daily.text
districts_daily = json.loads(districts_daily)
View plotlylinechart.py
import plotly.express as px
fig = px.line(df, x="date", y=["totalactive",'totalrecovered','totaldeceased'],
log_y= True, title='Total Coronavirus Cases in India')
fig.show()
View plotlygeojson.py
with open('Indian_States.txt') as f:
statejson = json.load(f)
fig = px.choropleth_mapbox(statedf, geojson=statejson, color="active",
locations="state", featureidkey="properties.NAME_1",
center={"lat": 23.2599, "lon": 77.4126},
mapbox_style="carto-positron", zoom=3)
fig.update_layout(margin={"r":0,"t":0,"l":0,"b":0})
fig.show()
View plotlyanimation.py
px.scatter(data2, x="totalconfirmed", y="totaldeceased",
animation_frame=data2.date.astype(str), animation_group="state",
size="totaltested", color="state", hover_name="state",
range_x=[0,450000], range_y=[0,16000]
)
View base.html
<script>
// set the dimensions and margins of the graph
var margin = {top: 10, right: 30, bottom: 30, left: 60},
width = 460 - margin.left - margin.right,
height = 400 - margin.top - margin.bottom;
// append the svg object to the body of the page
var svg = d3.select("#my_dataviz")
.append("svg")
View growth.py
monthwise = df.groupby(['district','month']).last()['confirmed'].unstack()
monthwise['growth'] = monthwise[5]/monthwise[4]
growth = monthwise.drop(6, axis=1)[monthwise[5]>1000].dropna(subset=['growth'])
growth = growth.sort_values(by=['growth'], ascending = False)
growth.rename(columns ={4: 'Last day of April', 5: 'Last day of May'})
View districtsdaily.py
districts_daily = requests.get('https://api.covid19india.org/districts_daily.json')
districts_daily = districts_daily.text
districts_daily = json.loads(districts_daily)
states = []; districts = []; dates = []; active = []; confirmed = []
deceased = []; recovered = []
for state in districts_daily["districtsDaily"]:
for district in districts_daily["districtsDaily"][state]:
for day in districts_daily["districtsDaily"][state][district]:
states.append(state)
districts.append(district)
View dailytests.py
stateslist = ['Maharashtra', 'Gujarat', 'Delhi', 'Karnataka', 'Kerala', 'West Bengal']
for state in stateslist:
statedata = data[data['state']==state]
plt.plot(statedata['Dates'][-15:], statedata['dailytested'][-15:], label=state)
plt.title('Daily Tests ')
plt.legend()
plt.show()
You can’t perform that action at this time.