Difference makes the DIFFERENCE
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
plt.style.use(['dark_background'])
import seaborn as sns
sns.set(color_codes = True)
Pie Chart
pen = sns.load_dataset('penguins')
pen.head(2)
pen.groupby('species').count()
pen.groupby('species')['species'].count()
c = pen.groupby('species')['species'].count()
c
plt.pie(c)
plt.show()
plt.pie(c, labels = c.index, autopct="%.2f%%")
plt.show()
plt.pie(c, labels = c.index, autopct="%.2f%%", explode=[0,1,0], startangle = 180)
plt.show()
plt.pie(np.random.randint(0, 10, 10), autopct="%.2f%%", pctdistance=1);
plt.pie(np.random.randint(0, 10, 10));
plt.show()
plt.pie(np.random.randint(1, 10, 10), wedgeprops=dict(width=0.25));
https://matplotlib.org/stable/tutorials/colors/colormaps.html
cmap = plt.get_cmap('Paired')
my_colors = cmap(np.arange(10))
plt.pie(np.random.randint(1, 10, 10),
wedgeprops=dict(width=0.25),
colors = my_colors);
c
plt.pie(c, labels = c.index,
autopct = "%.2f%%",
wedgeprops=dict(width=0.25), colors = my_colors);
c_i = pen.groupby('island')['island'].count()
c_i
plt.pie(c_i, labels = c_i.index, autopct="%0.2f",
wedgeprops = dict(width=0.3),
colors = my_colors);
cmap = plt.get_cmap('tab10')
my_colors = cmap(np.arange(10))
plt.pie(c_i, autopct="%0.2f%%", labels = c_i.index,
wedgeprops=dict(width=0.3));
pd.crosstab(pen.species, pen.island)
species_count = pd.crosstab(pen.species, pen.island)
species_count
species_count = species_count.T
sc = species_count
sc # island as index and the corresponding cols as values
plt.pie(sc.sum(axis=1), labels = sc.index,
radius = 1, wedgeprops=dict(width=.3));
plt.pie(sc.sum(axis=1), labels = sc.index,
radius = 1, wedgeprops=dict(width=.3));
plt.pie(sc.values.flatten(), radius=0.7, wedgeprops = dict(width=0.3));
cmap = plt.get_cmap('tab20c')
outer_colors = cmap(np.array([0, 4, 8]))
inner_colors = cmap(np.array([1,2,35,6,7, 9, 10, 11]))
plt.pie(sc.sum(axis=1), labels = sc.index,
radius = 1, wedgeprops=dict(width=.3), colors = outer_colors);
plt.pie(sc.values.flatten(), radius=0.7,
wedgeprops = dict(width=0.3), colors = inner_colors);
plt.pie(sc.sum(axis=1), labels = sc.index,
radius = 1, wedgeprops=dict(width=.3), colors = outer_colors);
plt.pie(sc.values.flatten(), radius=0.7,
labels = ['A,', 'C', 'G', 'A,', 'C', 'G', 'A,', 'C', 'G' ],
wedgeprops = dict(width=0.3), colors = inner_colors);
plt.pie(sc.sum(axis=1), labels = sc.index,
radius = 1, wedgeprops=dict(width=.3), colors = outer_colors);
plt.pie(sc.values.flatten(), radius=0.7,
labels = ['A,', '', 'G', 'A,', 'C', '', 'A,', '', '' ],
wedgeprops = dict(width=0.3), colors = inner_colors,
labeldistance = 0.8);
cmap = plt.get_cmap('tab20b')
outer_colors = cmap(np.array([0, 4, 8]))
inner_colors = cmap(np.array([1,2,35,6,7, 9, 10, 11]))
plt.pie(sc.sum(axis=1), labels = sc.index,
radius = 1, wedgeprops=dict(width=.3), colors = outer_colors);
plt.pie(sc.values.flatten(), radius=0.7,
labels = ['A,', '', 'G', 'A,', 'C', '', 'A,', '', '' ],
wedgeprops = dict(width=0.3), colors = inner_colors,
labeldistance = 0.8);
cmap = plt.get_cmap('tab20b')
outer_colors = cmap(np.array([0, 4, 8]))
inner_colors = cmap(np.array([1,2,35,6,7, 9, 10, 11]))
plt.pie(sc.sum(axis=1), labels = sc.index,
radius = 1, wedgeprops=dict(width=.3), colors = outer_colors);
plt.pie(sc.values.flatten(), radius=0.7,
labels = ['A,', '', 'G', 'A,', 'C', '', 'A,', '', '' ],
wedgeprops = dict(width=0.3), colors = inner_colors,
labeldistance = 0.8,
textprops = dict(color='w'));
import json
import urllib.request
url = 'https://api.covid19india.org/states_daily.json'
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)
df_ = df.tail(3)
df_
df_.drop('dateymd', inplace=True, axis=1)
df_.head(2)
df_.drop('tt', inplace = True, axis=1)
df_.head(2)
df_.drop('date', axis=1, inplace=True)
df_.set_index('status', inplace = True)
df_ = df_.T
df_
df_ = df_.apply(pd.to_numeric)
df_ = df_.T
df_.head(2)
!pip install nbconvert
%shell jupyter nbconvert --to html /content/testfile.ipynb