import numpy as np
import seaborn as sns
import matplotlib.pyplot as plt
import plotly.graph_objects as go
import pandas as pd
import warnings
warnings.filterwarnings("ignore")
def custom_pallete(custom_colors):
customPalette = sns.set_palette(sns.color_palette(custom_colors))
sns.palplot(sns.color_palette(custom_colors),size=0.8)
plt.tick_params(axis='both', labelsize=0, length = 0)
red = ["#4f000b","#720026","#ce4257","#ff7f51","#ff9b54"]
bo = ["#6930c3","#5e60ce","#0096c7","#48cae4","#ade8f4","#ff7f51","#ff9b54","#ffbf69"]
pink = ["#aa4465","#dd2d4a","#f26a8d","#f49cbb","#ffcbf2","#e2afff","#ff86c8","#ffa3a5","#ffbf81","#e9b827","#f9e576"]
pastel = sns.color_palette("Pastel1")
custom_pallete(pink)
Women = pd.read_csv("data.csv")
fig = go.Figure(data=[go.Table(
header=dict(values=list(["Full Name","Description",'Job','Death Method','Death Reason']),
fill_color=pink[3],
line_color='black',
align='center'),
cells=dict(values=[Women['Full Name'],Women['Description'],Women['Job'],Women['Death Method'],Women['Death Reason']],
fill_color="white",
line_color='black',
align='left'))
])
fig.show()
#@from Ayush Garg notebook
NA = pd.DataFrame(data=[Women.isna().sum().tolist(), ["{:.2f}".format(i)+'%' \
for i in (Women.isna().sum()/Women.shape[0]*100).tolist()]],
columns=Women.columns, index=['NA Count', 'NA Percent']).transpose()
NA.style.background_gradient(cmap="Pastel1", subset=['NA Count'])
f, (ax1, ax2) = plt.subplots(1, 2, figsize=(15, 10))
birthday = Women["Birth Date"].dropna().value_counts()[:10]
deathday = Women["Death Date"].dropna().value_counts()[:10]
sns.barplot(x=birthday,y=birthday.index,palette='Pastel1',ax=ax1)
sns.barplot(x=deathday,y=deathday.index,palette='Pastel1',ax=ax2)
sns.despine(bottom=True,left=True)
ax1.set(title='Counts of BirthDays');
ax2.set(title='Counts of Death Days');
fig, ax = plt.subplots(figsize=(16, 8))
fig.suptitle('Death Methods', size = 20, color = "black")
explode = ( 0.05, 0.3, 0.05, 0.05, 0.05)
labels = ["Natural Causes","Sucide","Homicide","Accident","Murdered"]
sizes = Women["Death Method"].dropna().value_counts()
ax.pie(sizes, explode=explode, colors=sns.color_palette("Pastel1"), startangle=60, labels=labels,autopct='%1.0f%%', pctdistance=0.9)
ax.add_artist(plt.Circle((0,0),0.4,fc='white'))
plt.show()
Jobs = Women["Job"].dropna().value_counts()[:10]
f, ax5 = plt.subplots(1, 1, figsize=(10, 7.5))
sns.barplot(x=Jobs,y=Jobs.index,palette='Pastel1',orient='h',ax=ax5)
sns.despine(bottom=True,left=True)
ax5.set(title='Top Ten Jobs');
sns.set_theme(style="whitegrid")
used_networks = [2,13,14]
df = Women.iloc[:,used_networks].value_counts().\
rename_axis(['Job','Death Method','Death Reason']).reset_index(name='counts')[:19]
# Draw each cell as a scatter point with varying size and color
g = sns.relplot(
data=df,
x="Job", y="counts",
hue="Death Method", size="Death Reason",
palette='Pastel1', sizes=(10, 400),alpha=1,height=8,aspect=1
)
plt.xticks(rotation=90)
g.set(ylabel="",title="Relation Between Jobs and Death")
g.despine(left=True, bottom=True);
New_women=Women.copy()
Topjobs = ["Actor","Film Actor","Politician","Singer"]
TopDeaths = ["Natural Causes","Suicide","Accident","Homicide"]
New_women=New_women[New_women["Job"].isin(Topjobs)]
New_women=New_women[New_women["Death Method"].isin(TopDeaths)]
fig, ax = plt.subplots(1, 1, figsize=(10, 7.5))
ax.axis('equal')
width = 0.3
cm = plt.get_cmap("Pastel1")
cout = cm(np.arange(3)*1)
pie, _ = ax.pie([39,7,9,4], radius=1, labels=list(["Actor","Film Actor","Politician","Singer"]), colors=cout)
plt.setp( pie, width=width, edgecolor='white')
cin = cm(np.array([1,3,5,7]))
labels = list(["Natural Causes","Suicide","Accident","Homicide"])
pie2, _ = ax.pie([58,18,6,17], radius=1-width, labels=labels,
labeldistance=0.7, colors=cin)
plt.setp( pie2, width=width, edgecolor='white')
plt.show()