In [76]:
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
from matplotlib import style
plt.style.use('dark_background')
import seaborn as sns
sns.set(color_codes=True)
In [77]:
p=sns.load_dataset('penguins')
In [78]:
p[p.species=='Adelie'].count()
Out[78]:
species 152 island 152 bill_length_mm 151 bill_depth_mm 151 flipper_length_mm 151 body_mass_g 151 sex 146 dtype: int64
In [79]:
c=p.groupby('species').count()
In [80]:
d=p.groupby('species')['species'].count()
In [81]:
plt.pie(d);
plt.show()
In [82]:
plt.pie(d,labels=c.index);
plt.show()
In [83]:
plt.pie(d,labels=c.index,autopct='%.2f%%',explode=[0,1,0],startangle=180);
plt.show()
In [84]:
plt.pie(np.random.randint(0,10,10),wedgeprops=dict(width=0.3));
plt.show()
In [85]:
cmap=plt.get_cmap('Accent')
my_colors=cmap(np.arange(10))
In [86]:
plt.pie(np.random.randint(0,10,10),wedgeprops=dict(width=0.3),colors=my_colors)
plt.show()
In [87]:
plt.pie(d,labels=c.index,autopct='%.2f%%',wedgeprops=dict(width=0.3),colors=my_colors);
plt.show()
In [88]:
c_i=p.groupby('island')['island'].count()
In [89]:
plt.pie(c_i,labels=c_i.index,autopct='%.2f%%',wedgeprops=dict(width=0.3),colors=my_colors);
plt.show()
In [90]:
s=pd.crosstab(p.species,p.island)
In [91]:
s_i=s.T
In [92]:
plt.pie(c.sum(axis=1),labels=s_i.index,radius=1,wedgeprops=dict(width=0.3));
plt.pie(c_i.values.flatten(),radius=0.7,wedgeprops=dict(width=0.3));
In [93]:
cmaps=plt.get_cmap('tab20c')
outer_color=cmaps(np.array([0,4,8]))
inner_color=cmaps(np.array([1,2,3,5,6,7,9,10,11]))
In [94]:
plt.pie(s_i.sum(axis=1),labels=c.index,radius=1,wedgeprops=dict(width=0.3),colors=outer_color);
plt.pie(s_i.values.flatten(),labels=['A','','G','A','C','','A','',''],radius=0.7,wedgeprops=dict(width=0.3),colors=inner_color);
In [95]:
plt.pie(s_i.sum(axis=1),labels=c.index,radius=1,wedgeprops=dict(width=0.3),colors=outer_color);
plt.pie(s_i.values.flatten(),labels=['A','','G','A','C','','A','',''],radius=0.7,wedgeprops=dict(width=0.3),colors=inner_color,labeldistance=0.7);
In [96]:
import json
url='https://api.covid19india.org/states_daily.json'
import urllib.request
urllib.request.urlretrieve(url,'data.json')
with open('data.json') as f:
data=json.load(f)
data=data['states_daily']
df=pd.json_normalize(data)
In [97]:
df.info()
<class 'pandas.core.frame.DataFrame'> RangeIndex: 1365 entries, 0 to 1364 Data columns (total 42 columns): # Column Non-Null Count Dtype --- ------ -------------- ----- 0 an 1365 non-null object 1 ap 1365 non-null object 2 ar 1365 non-null object 3 as 1365 non-null object 4 br 1365 non-null object 5 ch 1365 non-null object 6 ct 1365 non-null object 7 date 1365 non-null object 8 dateymd 1365 non-null object 9 dd 1365 non-null object 10 dl 1365 non-null object 11 dn 1365 non-null object 12 ga 1365 non-null object 13 gj 1365 non-null object 14 hp 1365 non-null object 15 hr 1365 non-null object 16 jh 1365 non-null object 17 jk 1365 non-null object 18 ka 1365 non-null object 19 kl 1365 non-null object 20 la 1365 non-null object 21 ld 1365 non-null object 22 mh 1365 non-null object 23 ml 1365 non-null object 24 mn 1365 non-null object 25 mp 1365 non-null object 26 mz 1365 non-null object 27 nl 1365 non-null object 28 or 1365 non-null object 29 pb 1365 non-null object 30 py 1365 non-null object 31 rj 1365 non-null object 32 sk 1365 non-null object 33 status 1365 non-null object 34 tg 1365 non-null object 35 tn 1365 non-null object 36 tr 1365 non-null object 37 tt 1365 non-null object 38 un 1365 non-null object 39 up 1365 non-null object 40 ut 1365 non-null object 41 wb 1365 non-null object dtypes: object(42) memory usage: 448.0+ KB
In [98]:
df.head()
Out[98]:
| an | ap | ar | as | br | ch | ct | date | dateymd | dd | ... | sk | status | tg | tn | tr | tt | un | up | ut | wb | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 14-Mar-20 | 2020-03-14 | 0 | ... | 0 | Confirmed | 1 | 1 | 0 | 81 | 0 | 12 | 0 | 0 |
| 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 14-Mar-20 | 2020-03-14 | 0 | ... | 0 | Recovered | 0 | 0 | 0 | 9 | 0 | 4 | 0 | 0 |
| 2 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 14-Mar-20 | 2020-03-14 | 0 | ... | 0 | Deceased | 0 | 0 | 0 | 2 | 0 | 0 | 0 | 0 |
| 3 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 15-Mar-20 | 2020-03-15 | 0 | ... | 0 | Confirmed | 2 | 0 | 0 | 27 | 0 | 1 | 0 | 0 |
| 4 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 15-Mar-20 | 2020-03-15 | 0 | ... | 0 | Recovered | 1 | 0 | 0 | 4 | 0 | 0 | 0 | 0 |
5 rows × 42 columns
In [99]:
t=sns.load_dataset('tips')
In [100]:
t.head()
Out[100]:
| total_bill | tip | sex | smoker | day | time | size | |
|---|---|---|---|---|---|---|---|
| 0 | 16.99 | 1.01 | Female | No | Sun | Dinner | 2 |
| 1 | 10.34 | 1.66 | Male | No | Sun | Dinner | 3 |
| 2 | 21.01 | 3.50 | Male | No | Sun | Dinner | 3 |
| 3 | 23.68 | 3.31 | Male | No | Sun | Dinner | 2 |
| 4 | 24.59 | 3.61 | Female | No | Sun | Dinner | 4 |
In [102]:
x=sns.scatterplot(x='total_bill', y='tip',data=t)
In [103]:
t['fractiontip']=t['tip']/t['total_bill']
In [104]:
x=sns.scatterplot(x='total_bill', y='fractiontip',data=t)
In [105]:
x=sns.scatterplot(x='total_bill',y='tip',hue='time',data=t)
In [110]:
x=sns.scatterplot(x='total_bill',y='tip',hue='size',style='sex',data=t, palette='viridis')
In [112]:
x=sns.scatterplot(x='total_bill',y='tip',hue='size',style='sex',size='size',data=t, palette = 'viridis')
In [114]:
x=sns.scatterplot(x='total_bill',y='tip',hue='size',style='sex',size='size',data=t, palette = 'viridis')
plt.legend(bbox_to_anchor=(1.05,1))
Out[114]:
<matplotlib.legend.Legend at 0x2b1fc2320d0>
In [115]:
d=sns.load_dataset('diamonds');
In [119]:
d.describe()
Out[119]:
| carat | depth | table | price | x | y | z | |
|---|---|---|---|---|---|---|---|
| count | 53940.000000 | 53940.000000 | 53940.000000 | 53940.000000 | 53940.000000 | 53940.000000 | 53940.000000 |
| mean | 0.797940 | 61.749405 | 57.457184 | 3932.799722 | 5.731157 | 5.734526 | 3.538734 |
| std | 0.474011 | 1.432621 | 2.234491 | 3989.439738 | 1.121761 | 1.142135 | 0.705699 |
| min | 0.200000 | 43.000000 | 43.000000 | 326.000000 | 0.000000 | 0.000000 | 0.000000 |
| 25% | 0.400000 | 61.000000 | 56.000000 | 950.000000 | 4.710000 | 4.720000 | 2.910000 |
| 50% | 0.700000 | 61.800000 | 57.000000 | 2401.000000 | 5.700000 | 5.710000 | 3.530000 |
| 75% | 1.040000 | 62.500000 | 59.000000 | 5324.250000 | 6.540000 | 6.540000 | 4.040000 |
| max | 5.010000 | 79.000000 | 95.000000 | 18823.000000 | 10.740000 | 58.900000 | 31.800000 |
In [120]:
d.info()
<class 'pandas.core.frame.DataFrame'> RangeIndex: 53940 entries, 0 to 53939 Data columns (total 10 columns): # Column Non-Null Count Dtype --- ------ -------------- ----- 0 carat 53940 non-null float64 1 cut 53940 non-null category 2 color 53940 non-null category 3 clarity 53940 non-null category 4 depth 53940 non-null float64 5 table 53940 non-null float64 6 price 53940 non-null int64 7 x 53940 non-null float64 8 y 53940 non-null float64 9 z 53940 non-null float64 dtypes: category(3), float64(6), int64(1) memory usage: 3.0 MB
In [117]:
d.head(3)
Out[117]:
| carat | cut | color | clarity | depth | table | price | x | y | z | |
|---|---|---|---|---|---|---|---|---|---|---|
| 0 | 0.23 | Ideal | E | SI2 | 61.5 | 55.0 | 326 | 3.95 | 3.98 | 2.43 |
| 1 | 0.21 | Premium | E | SI1 | 59.8 | 61.0 | 326 | 3.89 | 3.84 | 2.31 |
| 2 | 0.23 | Good | E | VS1 | 56.9 | 65.0 | 327 | 4.05 | 4.07 | 2.31 |
In [118]:
sns.barplot(x='x',y='price',data=d.sample(1000))
Out[118]:
<Axes: xlabel='x', ylabel='price'>
In [121]:
d['x_q']=pd.cut(d['x'],bins=15)
In [122]:
d.head()
Out[122]:
| carat | cut | color | clarity | depth | table | price | x | y | z | x_q | |
|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | 0.23 | Ideal | E | SI2 | 61.5 | 55.0 | 326 | 3.95 | 3.98 | 2.43 | (3.58, 4.296] |
| 1 | 0.21 | Premium | E | SI1 | 59.8 | 61.0 | 326 | 3.89 | 3.84 | 2.31 | (3.58, 4.296] |
| 2 | 0.23 | Good | E | VS1 | 56.9 | 65.0 | 327 | 4.05 | 4.07 | 2.31 | (3.58, 4.296] |
| 3 | 0.29 | Premium | I | VS2 | 62.4 | 58.0 | 334 | 4.20 | 4.23 | 2.63 | (3.58, 4.296] |
| 4 | 0.31 | Good | J | SI2 | 63.3 | 58.0 | 335 | 4.34 | 4.35 | 2.75 | (4.296, 5.012] |
In [ ]:
d['x_q'].unique()
In [124]:
sns.barplot(x='x_q',y='price',data=d.sample(1000))
plt.xticks(rotation=45, ha='right')
Out[124]:
([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14], [Text(0, 0, '(-0.0107, 0.716]'), Text(1, 0, '(0.716, 1.432]'), Text(2, 0, '(1.432, 2.148]'), Text(3, 0, '(2.148, 2.864]'), Text(4, 0, '(2.864, 3.58]'), Text(5, 0, '(3.58, 4.296]'), Text(6, 0, '(4.296, 5.012]'), Text(7, 0, '(5.012, 5.728]'), Text(8, 0, '(5.728, 6.444]'), Text(9, 0, '(6.444, 7.16]'), Text(10, 0, '(7.16, 7.876]'), Text(11, 0, '(7.876, 8.592]'), Text(12, 0, '(8.592, 9.308]'), Text(13, 0, '(9.308, 10.024]'), Text(14, 0, '(10.024, 10.74]')])
In [125]:
d['x']
Out[125]:
0 3.95
1 3.89
2 4.05
3 4.20
4 4.34
...
53935 5.75
53936 5.69
53937 5.66
53938 6.15
53939 5.83
Name: x, Length: 53940, dtype: float64
In [126]:
d[['x','y','z']].mean()
Out[126]:
x 5.731157 y 5.734526 z 3.538734 dtype: float64
In [127]:
d['x_q']=pd.cut(d['x'],bins=15)
In [128]:
d.head()
Out[128]:
| carat | cut | color | clarity | depth | table | price | x | y | z | x_q | |
|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | 0.23 | Ideal | E | SI2 | 61.5 | 55.0 | 326 | 3.95 | 3.98 | 2.43 | (3.58, 4.296] |
| 1 | 0.21 | Premium | E | SI1 | 59.8 | 61.0 | 326 | 3.89 | 3.84 | 2.31 | (3.58, 4.296] |
| 2 | 0.23 | Good | E | VS1 | 56.9 | 65.0 | 327 | 4.05 | 4.07 | 2.31 | (3.58, 4.296] |
| 3 | 0.29 | Premium | I | VS2 | 62.4 | 58.0 | 334 | 4.20 | 4.23 | 2.63 | (3.58, 4.296] |
| 4 | 0.31 | Good | J | SI2 | 63.3 | 58.0 | 335 | 4.34 | 4.35 | 2.75 | (4.296, 5.012] |
In [131]:
sns.barplot(x='x_q',y='price',data=d.sample(1000))
plt.xticks(rotation=90, ha='right')
Out[131]:
([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14], [Text(0, 0, '(-0.0107, 0.716]'), Text(1, 0, '(0.716, 1.432]'), Text(2, 0, '(1.432, 2.148]'), Text(3, 0, '(2.148, 2.864]'), Text(4, 0, '(2.864, 3.58]'), Text(5, 0, '(3.58, 4.296]'), Text(6, 0, '(4.296, 5.012]'), Text(7, 0, '(5.012, 5.728]'), Text(8, 0, '(5.728, 6.444]'), Text(9, 0, '(6.444, 7.16]'), Text(10, 0, '(7.16, 7.876]'), Text(11, 0, '(7.876, 8.592]'), Text(12, 0, '(8.592, 9.308]'), Text(13, 0, '(9.308, 10.024]'), Text(14, 0, '(10.024, 10.74]')])
In [132]:
d['x_q_z']=d['x_q'].apply(np.mean)
In [133]:
d.head()
Out[133]:
| carat | cut | color | clarity | depth | table | price | x | y | z | x_q | x_q_z | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | 0.23 | Ideal | E | SI2 | 61.5 | 55.0 | 326 | 3.95 | 3.98 | 2.43 | (3.58, 4.296] | (3.58, 4.296] |
| 1 | 0.21 | Premium | E | SI1 | 59.8 | 61.0 | 326 | 3.89 | 3.84 | 2.31 | (3.58, 4.296] | (3.58, 4.296] |
| 2 | 0.23 | Good | E | VS1 | 56.9 | 65.0 | 327 | 4.05 | 4.07 | 2.31 | (3.58, 4.296] | (3.58, 4.296] |
| 3 | 0.29 | Premium | I | VS2 | 62.4 | 58.0 | 334 | 4.20 | 4.23 | 2.63 | (3.58, 4.296] | (3.58, 4.296] |
| 4 | 0.31 | Good | J | SI2 | 63.3 | 58.0 | 335 | 4.34 | 4.35 | 2.75 | (4.296, 5.012] | (4.296, 5.012] |
In [134]:
f=sns.load_dataset('fmri')
f.head()
Out[134]:
| subject | timepoint | event | region | signal | |
|---|---|---|---|---|---|
| 0 | s13 | 18 | stim | parietal | -0.017552 |
| 1 | s5 | 14 | stim | parietal | -0.080883 |
| 2 | s12 | 18 | stim | parietal | -0.081033 |
| 3 | s11 | 18 | stim | parietal | -0.046134 |
| 4 | s10 | 18 | stim | parietal | -0.037970 |
In [135]:
sns.lineplot(x='timepoint',y='signal',data=f)
Out[135]:
<Axes: xlabel='timepoint', ylabel='signal'>
In [137]:
sns.lineplot(x='timepoint',y='signal',hue='region',data=f)
Out[137]:
<Axes: xlabel='timepoint', ylabel='signal'>
In [138]:
sns.lineplot(x='timepoint',y='signal',hue='event',data=f,style='region')
Out[138]:
<Axes: xlabel='timepoint', ylabel='signal'>
In [139]:
sns.lineplot(x='timepoint',y='signal',data=f,marker=True)
Out[139]:
<Axes: xlabel='timepoint', ylabel='signal'>
In [140]:
sns.lineplot(x='timepoint',y='signal',data=f,marker=True,estimator=np.median)
Out[140]:
<Axes: xlabel='timepoint', ylabel='signal'>
In [141]:
sns.lineplot(x='timepoint',y='signal',data=f,units='subject',estimator=None);
In [144]:
f_= f[(f.region=='parietal') & (f.event=='cue')]
In [145]:
f_.head()
Out[145]:
| subject | timepoint | event | region | signal | |
|---|---|---|---|---|---|
| 532 | s3 | 4 | cue | parietal | 0.058219 |
| 533 | s6 | 5 | cue | parietal | 0.038145 |
| 534 | s7 | 5 | cue | parietal | -0.008158 |
| 535 | s8 | 5 | cue | parietal | 0.047136 |
| 536 | s9 | 5 | cue | parietal | 0.055847 |
In [146]:
sns.lineplot(x='timepoint',y='signal',data=f_,units='subject',estimator=None);
In [147]:
sns.lineplot(x='timepoint',y='signal',data=f_,hue='subject',estimator=None);
In [149]:
import json
import pandas as pd
In [150]:
url='https://api.covid19india.org/states_daily.json'
import urllib.request
urllib.request.urlretrieve(url,'data.json')
Out[150]:
('data.json', <http.client.HTTPMessage at 0x2b1806d3a50>)
In [151]:
with open('data.json') as f: data=json.load(f)
data=data['states_daily']
In [153]:
df = pd.json_normalize(data)
df['date'] = pd.to_datetime(df['date'])
df.drop('tt', axis=1, inplace=True)
df.set_index('date', inplace=True)
df = df[df['status'] == 'Confirmed']
df.drop('status', axis=1, inplace=True)
df = df.apply(pd.to_numeric,errors='coerce')
df = df.rolling(7).mean()
df.reset_index(inplace=True)
C:\Users\Flynas54223\AppData\Local\Temp\ipykernel_23524\4275538909.py:2: UserWarning: Could not infer format, so each element will be parsed individually, falling back to `dateutil`. To ensure parsing is consistent and as-expected, please specify a format. df['date'] = pd.to_datetime(df['date'])
In [155]:
df.describe()
Out[155]:
| date | an | ap | ar | as | br | ch | ct | dateymd | dd | ... | py | rj | sk | tg | tn | tr | un | up | ut | wb | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| count | 455 | 449.000000 | 449.000000 | 449.000000 | 449.000000 | 449.000000 | 449.000000 | 449.000000 | 0.0 | 449.0 | ... | 449.000000 | 449.000000 | 449.000000 | 449.000000 | 449.000000 | 449.000000 | 449.000000 | 449.000000 | 449.000000 | 449.000000 |
| mean | 2020-10-27 00:00:00 | 15.933503 | 3947.085587 | 66.732739 | 985.967229 | 1591.151129 | 135.385301 | 2188.841553 | NaN | 0.0 | ... | 245.269488 | 2110.031817 | 38.900414 | 1323.937957 | 5062.322940 | 125.284760 | 0.000000 | 3785.471842 | 745.935730 | 3200.332485 |
| min | 2020-03-14 00:00:00 | 0.000000 | 0.428571 | 0.000000 | 0.000000 | 0.000000 | 0.000000 | 0.000000 | NaN | 0.0 | ... | 0.000000 | 2.428571 | 0.000000 | 2.714286 | 0.428571 | 0.000000 | -518.571429 | 2.285714 | -24.000000 | 0.285714 |
| 25% | 2020-07-05 12:00:00 | 1.000000 | 118.000000 | 0.428571 | 21.571429 | 116.428571 | 11.714286 | 105.142857 | NaN | 0.0 | ... | 21.428571 | 224.428571 | 1.857143 | 164.285714 | 613.285714 | 3.714286 | 0.000000 | 236.428571 | 57.142857 | 247.142857 |
| 50% | 2020-10-27 00:00:00 | 6.714286 | 773.428571 | 11.857143 | 186.857143 | 551.142857 | 62.142857 | 995.000000 | NaN | 0.0 | ... | 47.000000 | 912.714286 | 18.571429 | 823.571429 | 1964.428571 | 33.142857 | 0.000000 | 1324.142857 | 264.857143 | 1782.000000 |
| 75% | 2021-02-17 12:00:00 | 18.714286 | 7165.714286 | 87.285714 | 1671.285714 | 1480.571429 | 149.857143 | 2262.571429 | NaN | 0.0 | ... | 351.428571 | 1897.285714 | 36.714286 | 1863.428571 | 5619.571429 | 156.000000 | 0.000000 | 3846.571429 | 572.142857 | 3404.428571 |
| max | 2021-06-11 00:00:00 | 137.714286 | 22051.000000 | 415.857143 | 5805.857143 | 14191.285714 | 843.000000 | 15583.428571 | NaN | 0.0 | ... | 1853.857143 | 17590.428571 | 302.142857 | 8036.285714 | 35306.571429 | 771.571429 | 492.000000 | 34813.142857 | 7554.714286 | 20085.000000 |
| std | NaN | 24.235497 | 5553.147526 | 96.919770 | 1473.221230 | 2911.695749 | 195.194670 | 3712.178172 | NaN | 0.0 | ... | 403.463288 | 3856.225590 | 67.646425 | 1624.568858 | 7912.107150 | 188.730885 | 119.620552 | 7147.473278 | 1477.842059 | 4790.895101 |
8 rows × 40 columns
In [154]:
df.info()
<class 'pandas.core.frame.DataFrame'> RangeIndex: 455 entries, 0 to 454 Data columns (total 40 columns): # Column Non-Null Count Dtype --- ------ -------------- ----- 0 date 455 non-null datetime64[ns] 1 an 449 non-null float64 2 ap 449 non-null float64 3 ar 449 non-null float64 4 as 449 non-null float64 5 br 449 non-null float64 6 ch 449 non-null float64 7 ct 449 non-null float64 8 dateymd 0 non-null float64 9 dd 449 non-null float64 10 dl 449 non-null float64 11 dn 449 non-null float64 12 ga 449 non-null float64 13 gj 449 non-null float64 14 hp 449 non-null float64 15 hr 449 non-null float64 16 jh 449 non-null float64 17 jk 449 non-null float64 18 ka 449 non-null float64 19 kl 449 non-null float64 20 la 449 non-null float64 21 ld 449 non-null float64 22 mh 449 non-null float64 23 ml 449 non-null float64 24 mn 449 non-null float64 25 mp 449 non-null float64 26 mz 449 non-null float64 27 nl 449 non-null float64 28 or 449 non-null float64 29 pb 449 non-null float64 30 py 449 non-null float64 31 rj 449 non-null float64 32 sk 449 non-null float64 33 tg 449 non-null float64 34 tn 449 non-null float64 35 tr 449 non-null float64 36 un 449 non-null float64 37 up 449 non-null float64 38 ut 449 non-null float64 39 wb 449 non-null float64 dtypes: datetime64[ns](1), float64(39) memory usage: 142.3 KB
In [ ]:
df.isna()
Out[Â ]:
| date | an | ap | ar | as | br | ch | ct | dd | dl | dn | ga | gj | hp | hr | jh | jk | ka | kl | la | ld | mh | ml | mn | mp | mz | nl | or | pb | py | rj | sk | tg | tn | tr | un | up | ut | wb | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | False | True | True | True | True | True | True | True | True | True | True | True | True | True | True | True | True | True | True | True | True | True | True | True | True | True | True | True | True | True | True | True | True | True | True | True | True | True | True |
| 1 | False | True | True | True | True | True | True | True | True | True | True | True | True | True | True | True | True | True | True | True | True | True | True | True | True | True | True | True | True | True | True | True | True | True | True | True | True | True | True |
| 2 | False | True | True | True | True | True | True | True | True | True | True | True | True | True | True | True | True | True | True | True | True | True | True | True | True | True | True | True | True | True | True | True | True | True | True | True | True | True | True |
| 3 | False | True | True | True | True | True | True | True | True | True | True | True | True | True | True | True | True | True | True | True | True | True | True | True | True | True | True | True | True | True | True | True | True | True | True | True | True | True | True |
| 4 | False | True | True | True | True | True | True | True | True | True | True | True | True | True | True | True | True | True | True | True | True | True | True | True | True | True | True | True | True | True | True | True | True | True | True | True | True | True | True |
| ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... |
| 516 | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False |
| 517 | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False |
| 518 | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False |
| 519 | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False |
| 520 | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False |
521 rows × 39 columns
In [157]:
############# ALTERNATIVE METHOD TO GET DATA FROM URL #########################
import pandas as pd
# 1. Fetch data directly from the updated data.covid19india.org archive
url = 'https://data.covid19india.org/csv/latest/state_wise_daily.csv'
df = pd.read_csv(url)
# 2. Filter for Confirmed cases
df = df[df['Status'] == 'Confirmed'].copy()
# 3. Format Date and set index
df['Date_YMD'] = pd.to_datetime(df['Date_YMD'])
df.set_index('Date_YMD', inplace=True)
# 4. Drop non-numeric columns ('Date' text column and 'Status' column)
df.drop(columns=['Date', 'Status', 'TT'], errors='ignore', inplace=True)
# 5. Convert all state data columns to numeric
df = df.apply(pd.to_numeric, errors='coerce')
# 6. Calculate 7-day rolling average
df_7day = df.rolling(7).mean().reset_index()
print(df_7day.head())
Date_YMD AN AP AR AS BR CH CT DN DD ... PB RJ SK TN TG TR \ 0 2020-03-14 NaN NaN NaN NaN NaN NaN NaN NaN NaN ... NaN NaN NaN NaN NaN NaN 1 2020-03-15 NaN NaN NaN NaN NaN NaN NaN NaN NaN ... NaN NaN NaN NaN NaN NaN 2 2020-03-16 NaN NaN NaN NaN NaN NaN NaN NaN NaN ... NaN NaN NaN NaN NaN NaN 3 2020-03-17 NaN NaN NaN NaN NaN NaN NaN NaN NaN ... NaN NaN NaN NaN NaN NaN 4 2020-03-18 NaN NaN NaN NaN NaN NaN NaN NaN NaN ... NaN NaN NaN NaN NaN NaN UP UT WB UN 0 NaN NaN NaN NaN 1 NaN NaN NaN NaN 2 NaN NaN NaN NaN 3 NaN NaN NaN NaN 4 NaN NaN NaN NaN [5 rows x 39 columns]
In [159]:
# Drop rows at index position 3 and 4 (4th and 5th rows)
df = df.drop(df.index[[3, 4]])
In [160]:
df.isna()
Out[160]:
| AN | AP | AR | AS | BR | CH | CT | DN | DD | DL | ... | PB | RJ | SK | TN | TG | TR | UP | UT | WB | UN | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Date_YMD | |||||||||||||||||||||
| 2020-03-14 | False | False | False | False | False | False | False | False | False | False | ... | False | False | False | False | False | False | False | False | False | False |
| 2020-03-15 | False | False | False | False | False | False | False | False | False | False | ... | False | False | False | False | False | False | False | False | False | False |
| 2020-03-16 | False | False | False | False | False | False | False | False | False | False | ... | False | False | False | False | False | False | False | False | False | False |
| 2020-03-19 | False | False | False | False | False | False | False | False | False | False | ... | False | False | False | False | False | False | False | False | False | False |
| 2020-03-20 | False | False | False | False | False | False | False | False | False | False | ... | False | False | False | False | False | False | False | False | False | False |
| ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... |
| 2021-10-27 | False | False | False | False | False | False | False | False | False | False | ... | False | False | False | False | False | False | False | False | False | False |
| 2021-10-28 | False | False | False | False | False | False | False | False | False | False | ... | False | False | False | False | False | False | False | False | False | False |
| 2021-10-29 | False | False | False | False | False | False | False | False | False | False | ... | False | False | False | False | False | False | False | False | False | False |
| 2021-10-30 | False | False | False | False | False | False | False | False | False | False | ... | False | False | False | False | False | False | False | False | False | False |
| 2021-10-31 | False | False | False | False | False | False | False | False | False | False | ... | False | False | False | False | False | False | False | False | False | False |
595 rows × 38 columns
In [161]:
import numpy as np
In [162]:
x=np.random.rand(10,10)
In [163]:
sns.heatmap(x)
Out[163]:
<Axes: >
In [164]:
t=sns.load_dataset('flights')
In [165]:
t.head()
Out[165]:
| year | month | passengers | |
|---|---|---|---|
| 0 | 1949 | Jan | 112 |
| 1 | 1949 | Feb | 118 |
| 2 | 1949 | Mar | 132 |
| 3 | 1949 | Apr | 129 |
| 4 | 1949 | May | 121 |
In [166]:
t_=t.pivot(index='year',columns='month',values='passengers')
In [167]:
t_.head()
Out[167]:
| month | Jan | Feb | Mar | Apr | May | Jun | Jul | Aug | Sep | Oct | Nov | Dec |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| year | ||||||||||||
| 1949 | 112 | 118 | 132 | 129 | 121 | 135 | 148 | 148 | 136 | 119 | 104 | 118 |
| 1950 | 115 | 126 | 141 | 135 | 125 | 149 | 170 | 170 | 158 | 133 | 114 | 140 |
| 1951 | 145 | 150 | 178 | 163 | 172 | 178 | 199 | 199 | 184 | 162 | 146 | 166 |
| 1952 | 171 | 180 | 193 | 181 | 183 | 218 | 230 | 242 | 209 | 191 | 172 | 194 |
| 1953 | 196 | 196 | 236 | 235 | 229 | 243 | 264 | 272 | 237 | 211 | 180 | 201 |
In [168]:
sns.heatmap(t_)
Out[168]:
<Axes: xlabel='month', ylabel='year'>
In [169]:
sns.heatmap(t_.T,annot=True,fmt='d')
Out[169]:
<Axes: xlabel='year', ylabel='month'>
In [170]:
fig=plt.gcf();
fig.set_size_inches(15,10)
sns.heatmap(t_.T,annot=True,fmt='d')
Out[170]:
<Axes: xlabel='year', ylabel='month'>
In [171]:
fig=plt.gcf();
fig.set_size_inches(15,10)
sns.heatmap(t_.T,annot=True,fmt='d',cmap='YlGnBu')
Out[171]:
<Axes: xlabel='year', ylabel='month'>
In [172]:
fig=plt.gcf();
fig.set_size_inches(15,10)
sns.heatmap(t_.T,annot=True,fmt='d',cmap=sns.diverging_palette(250,10,n=10))
Out[172]:
<Axes: xlabel='year', ylabel='month'>
In [173]:
fig=plt.gcf();
fig.set_size_inches(15,10)
sns.heatmap(t_.T,annot=True,fmt='d',cmap=sns.diverging_palette(50,200,n=10))
Out[173]:
<Axes: xlabel='year', ylabel='month'>
In [174]:
fig=plt.gcf();
fig.set_size_inches(15,10)
sns.heatmap(t_.T,annot=True,fmt='d',cmap=sns.diverging_palette(50,200,n=45))
Out[174]:
<Axes: xlabel='year', ylabel='month'>
In [184]:
import matplotlib.pyplot as plt
import seaborn as sns
fig = plt.gcf()
fig.set_size_inches(15, 10)
sns.heatmap(
t_.T,
annot=True,
fmt='d',
cmap=sns.diverging_palette(250, 10, n=45, as_cmap=True),
center=236 # Directly pass the target numerical value
)
Out[184]:
<Axes: xlabel='year', ylabel='month'>
In [185]:
!pip install nbconvert
Requirement already satisfied: nbconvert in C:\Users\Flynas54223\AppData\Local\Programs\Python\Python311\Lib\site-packages (7.16.6) Requirement already satisfied: beautifulsoup4 in C:\Users\Flynas54223\AppData\Local\Programs\Python\Python311\Lib\site-packages (from nbconvert) (4.13.4) Requirement already satisfied: bleach!=5.0.0 in C:\Users\Flynas54223\AppData\Local\Programs\Python\Python311\Lib\site-packages (from bleach[css]!=5.0.0->nbconvert) (6.2.0) Requirement already satisfied: defusedxml in C:\Users\Flynas54223\AppData\Local\Programs\Python\Python311\Lib\site-packages (from nbconvert) (0.7.1) Requirement already satisfied: jinja2>=3.0 in C:\Users\Flynas54223\AppData\Local\Programs\Python\Python311\Lib\site-packages (from nbconvert) (3.1.6) Requirement already satisfied: jupyter-core>=4.7 in C:\Users\Flynas54223\AppData\Local\Programs\Python\Python311\Lib\site-packages (from nbconvert) (5.7.2) Requirement already satisfied: jupyterlab-pygments in C:\Users\Flynas54223\AppData\Local\Programs\Python\Python311\Lib\site-packages (from nbconvert) (0.3.0) Requirement already satisfied: markupsafe>=2.0 in C:\Users\Flynas54223\AppData\Local\Programs\Python\Python311\Lib\site-packages (from nbconvert) (3.0.2) Requirement already satisfied: mistune<4,>=2.0.3 in C:\Users\Flynas54223\AppData\Local\Programs\Python\Python311\Lib\site-packages (from nbconvert) (3.1.3) Requirement already satisfied: nbclient>=0.5.0 in C:\Users\Flynas54223\AppData\Local\Programs\Python\Python311\Lib\site-packages (from nbconvert) (0.10.2) Requirement already satisfied: nbformat>=5.7 in C:\Users\Flynas54223\AppData\Local\Programs\Python\Python311\Lib\site-packages (from nbconvert) (5.10.4) Requirement already satisfied: packaging in C:\Users\Flynas54223\AppData\Local\Programs\Python\Python311\Lib\site-packages (from nbconvert) (25.0) Requirement already satisfied: pandocfilters>=1.4.1 in C:\Users\Flynas54223\AppData\Local\Programs\Python\Python311\Lib\site-packages (from nbconvert) (1.5.1) Requirement already satisfied: pygments>=2.4.1 in C:\Users\Flynas54223\AppData\Local\Programs\Python\Python311\Lib\site-packages (from nbconvert) (2.19.1) Requirement already satisfied: traitlets>=5.1 in C:\Users\Flynas54223\AppData\Local\Programs\Python\Python311\Lib\site-packages (from nbconvert) (5.14.3) Requirement already satisfied: webencodings in C:\Users\Flynas54223\AppData\Local\Programs\Python\Python311\Lib\site-packages (from bleach!=5.0.0->bleach[css]!=5.0.0->nbconvert) (0.5.1) Requirement already satisfied: tinycss2<1.5,>=1.1.0 in C:\Users\Flynas54223\AppData\Local\Programs\Python\Python311\Lib\site-packages (from bleach[css]!=5.0.0->nbconvert) (1.4.0) Requirement already satisfied: platformdirs>=2.5 in C:\Users\Flynas54223\AppData\Local\Programs\Python\Python311\Lib\site-packages (from jupyter-core>=4.7->nbconvert) (4.3.7) Requirement already satisfied: pywin32>=300 in C:\Users\Flynas54223\AppData\Local\Programs\Python\Python311\Lib\site-packages (from jupyter-core>=4.7->nbconvert) (310) Requirement already satisfied: jupyter-client>=6.1.12 in C:\Users\Flynas54223\AppData\Local\Programs\Python\Python311\Lib\site-packages (from nbclient>=0.5.0->nbconvert) (8.6.3) Requirement already satisfied: python-dateutil>=2.8.2 in C:\Users\Flynas54223\AppData\Local\Programs\Python\Python311\Lib\site-packages (from jupyter-client>=6.1.12->nbclient>=0.5.0->nbconvert) (2.9.0.post0) Requirement already satisfied: pyzmq>=23.0 in C:\Users\Flynas54223\AppData\Local\Programs\Python\Python311\Lib\site-packages (from jupyter-client>=6.1.12->nbclient>=0.5.0->nbconvert) (26.4.0) Requirement already satisfied: tornado>=6.2 in C:\Users\Flynas54223\AppData\Local\Programs\Python\Python311\Lib\site-packages (from jupyter-client>=6.1.12->nbclient>=0.5.0->nbconvert) (6.4.2) Requirement already satisfied: fastjsonschema>=2.15 in C:\Users\Flynas54223\AppData\Local\Programs\Python\Python311\Lib\site-packages (from nbformat>=5.7->nbconvert) (2.21.1) Requirement already satisfied: jsonschema>=2.6 in C:\Users\Flynas54223\AppData\Local\Programs\Python\Python311\Lib\site-packages (from nbformat>=5.7->nbconvert) (4.23.0) Requirement already satisfied: attrs>=22.2.0 in C:\Users\Flynas54223\AppData\Local\Programs\Python\Python311\Lib\site-packages (from jsonschema>=2.6->nbformat>=5.7->nbconvert) (25.3.0) Requirement already satisfied: jsonschema-specifications>=2023.03.6 in C:\Users\Flynas54223\AppData\Local\Programs\Python\Python311\Lib\site-packages (from jsonschema>=2.6->nbformat>=5.7->nbconvert) (2025.4.1) Requirement already satisfied: referencing>=0.28.4 in C:\Users\Flynas54223\AppData\Local\Programs\Python\Python311\Lib\site-packages (from jsonschema>=2.6->nbformat>=5.7->nbconvert) (0.36.2) Requirement already satisfied: rpds-py>=0.7.1 in C:\Users\Flynas54223\AppData\Local\Programs\Python\Python311\Lib\site-packages (from jsonschema>=2.6->nbformat>=5.7->nbconvert) (0.24.0) Requirement already satisfied: six>=1.5 in C:\Users\Flynas54223\AppData\Local\Programs\Python\Python311\Lib\site-packages (from python-dateutil>=2.8.2->jupyter-client>=6.1.12->nbclient>=0.5.0->nbconvert) (1.17.0) Requirement already satisfied: typing-extensions>=4.4.0 in C:\Users\Flynas54223\AppData\Local\Programs\Python\Python311\Lib\site-packages (from referencing>=0.28.4->jsonschema>=2.6->nbformat>=5.7->nbconvert) (4.13.2) Requirement already satisfied: soupsieve>1.2 in C:\Users\Flynas54223\AppData\Local\Programs\Python\Python311\Lib\site-packages (from beautifulsoup4->nbconvert) (2.7)
In [186]:
!jupyter nbconvert --to html FDS_W12_200709_181439.ipynb
[NbConvertApp] Converting notebook FDS_W12_200709_181439.ipynb to html [NbConvertApp] WARNING | Alternative text is missing on 36 image(s). [NbConvertApp] Writing 2878070 bytes to FDS_W12_200709_181439.html
In [ ]: