"""
# INTRODUCTION
1. Read datas
1. Poverty rate of each state
1. Most common 15 Name or Surname of killed people
1. High school graduation rate of the population that is older than 25 in states
1. Percentage of state's population according to races that are black,white,native american, asian and hispanic
1. High school graduation rate vs Poverty rate of each state
1. Kill properties
    * Manner of death
    * Kill weapon
    * Age of killed people
    * Race of killed people
    * Most dangerous cities
    * Most dangerous states
    * Having mental ilness or not for killed people
    * Threat types
    * Flee types
    * Having body cameras or not for police
1. Race rates according to states in kill data 
1. Kill numbers from states in kill data
1. Plotly Visualization Tutorial: https://www.kaggle.com/kanncaa1/plotly-tutorial-for-beginners
<br>
<br>
Plot Contents:
* [Bar Plot](#1)
* [Point Plot](#2)
* [Joint Plot](#3)
* [Pie Chart](#4)
* [Lm Plot](#5)
* [Kde Plot](#6)
* [Violin Plot](#7)
* [Heatmap](#8)
* [Box Plot](#9)
* [Swarm Plot](#10)
* [Pair Plot](#11)
* [Count Plot](#12)
    

"""
# This Python 3 environment comes with many helpful analytics libraries installed
# It is defined by the kaggle/python docker image: https://github.com/kaggle/docker-python
# For example, here's several helpful packages to load in 

import numpy as np # linear algebra
import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)
import seaborn as sns
import matplotlib.pyplot as plt
from collections import Counter
%matplotlib inline
# Input data files are available in the "../input/" directory.
# For example, running this (by clicking run or pressing Shift+Enter) will list the files in the input directory

from subprocess import check_output
print(check_output(["ls", "../input"]).decode("utf8"))

# Any results you write to the current directory are saved as output.
#read data
median_house_hold_in_come = pd.read_csv('../input/MedianHouseholdIncome2015.csv', encoding="windows-1252")
percentage_people_below_poverty_level = pd.read_csv('../input/PercentagePeopleBelowPovertyLevel.csv', encoding="windows-1252")
percent_over_25_completed_highSchool = pd.read_csv('../input/PercentOver25CompletedHighSchool.csv',encoding= "windows-1252")
share_race_city =pd.read_csv('../input/ShareRaceByCity.csv',encoding="windows-1252")



"""
#  Poverty rate of each state


"""
percentage_people_below_poverty_level.head()
percentage_people_below_poverty_level.info()
#percentage_people_below_poverty_level.poverty_rate.value_counts()
percentage_people_below_poverty_level.poverty_rate.replace(['-'], 0.0, inplace=True)
#percentage_people_below_poverty_level.poverty_rate.value_counts()
# Poverty rate of each state
percentage_people_below_poverty_level.poverty_rate.replace(['-'], 0.0, inplace=True)
percentage_people_below_poverty_level.poverty_rate = percentage_people_below_poverty_level.poverty_rate.astype(float)
area_list = list(percentage_people_below_poverty_level['Geographic Area'].unique())
area_poverty_ratio = []
varea_poverty_ratio = []
for i in area_list:
    x = percentage_people_below_poverty_level[percentage_people_below_poverty_level['Geographic Area']==i]
    area_poverty_rate = sum(x.poverty_rate)/len(x)
    area_poverty_ratio.append(area_poverty_rate)
data = pd.DataFrame({'area_list': area_list,'area_poverty_ratio':area_poverty_ratio})
new_index = (data['area_poverty_ratio'].sort_values(ascending=False)).index.values
sorted_data = data.reindex(new_index)
# visualization
# barplot
plt.figure(figsize=(15,16))
sns.barplot(x=sorted_data['area_list'], y=sorted_data['area_poverty_ratio'])
plt.xlabel("State")
plt.ylabel("Poverty rate")
plt.title("Poverty Rate Given States")
plt.xticks(rotation= 60)




area_poverty_rate = sum(x.poverty_rate)/len(x)
area_poverty_rate
#. High school graduation rate of the population that is older than 25 in states

percent_over_25_completed_highSchool.head()

percent_over_25_completed_highSchool.info()
#percent_over_25_completed_highSchool.percent_completed_hs.value_counts()
percent_over_25_completed_highSchool.percent_completed_hs.replace(['-'],0.0,inplace = True)
percent_over_25_completed_highSchool.percent_completed_hs = percent_over_25_completed_highSchool.percent_completed_hs.astype(float)
area_list = list(percent_over_25_completed_highSchool['Geographic Area'].unique())
area_highschool = []
for i in area_list:
    x = percent_over_25_completed_highSchool[percent_over_25_completed_highSchool['Geographic Area']==i]
    area_highschool_rate = sum(x.percent_completed_hs)/len(x)
    area_highschool.append(area_highschool_rate)
# sorting
data = pd.DataFrame({'area_list': area_list,'area_highschool_ratio':area_highschool})
new_index = (data['area_highschool_ratio'].sort_values(ascending=True)).index.values
sorted_data2 = data.reindex(new_index)

# visualization
plt.figure(figsize =(15,10))
sns.barplot(x = sorted_data2['area_list'], y = sorted_data2['area_highschool_ratio'])
plt.xticks(rotation= 90)
plt.xlabel("States")
plt.ylabel("High School Graduate Rate")
plt.title("Percentage of Given State's Population Above 25 that Has Graduated High School")

sorted_data.head()
# high school graduation rate vs Poverty rate of each state
sorted_data2["area_highschool_ratio"] =sorted_data2["area_highschool_ratio"]/max(sorted_data2["area_highschool_ratio"])
sorted_data["area_poverty_ratio"] =sorted_data["area_poverty_ratio"]/max(sorted_data["area_poverty_ratio"])

data =pd.concat([sorted_data,sorted_data2["area_highschool_ratio"]], axis = 1)
data.sort_values("area_poverty_ratio", inplace= True)

f,ax1 =plt.subplots(figsize = (20,10))
sns.pointplot(x = "area_list" , y = "area_poverty_ratio", data = data, color = "lime",alpha= 0.8)
sns.pointplot(x = "area_list" , y = "area_highschool_ratio", data = data, color = "red",alpha= 0.8)
plt.text(40,0.6 ,"high school graduate ratio", fontsize=17,color = "red",style ="italic")
plt.text(40,0.55,"poverty ratio",fontsize = 17, color ="lime",style="italic")

plt.xlabel("States", fontsize =15,color ="blue")
plt.ylabel("Value", fontsize =15,color ="blue")
plt.title("High School Graduate  VS  Poverty Rate",fontsize =15,color ="blue")
plt.grid()


"""
**jointplot**
"""
# jointplot 
#high school graduation rate vs Poverty rate of
g = sns.jointplot(data.area_poverty_ratio, data.area_highschool_ratio, kind ="kde", size=7)
plt.savefig("graph.png")
plt.show()


g=sns.jointplot(x ="area_poverty_ratio", y="area_highschool_ratio",data =data,ratio=3, size =6, color ="r")
"""
**Lm plot**
"""
 sns.lmplot( x ="area_poverty_ratio", y ="area_highschool_ratio",data =data)
plt.show()
"""
**Kde plot**
"""
data.head()
sns.kdeplot(data.area_poverty_ratio,data.area_highschool_ratio,shade=True,cut =6)
plt.show()
"""
**violin plot**
"""
pal = sns.cubehelix_palette(2, rot=-.5,dark=.6)
sns.violinplot(data=data,palette=pal,inner="points")
plt.show()
"""
**heatmap**
"""
f, ax = plt.subplots(figsize =(5,5))
sns.heatmap(data.corr(), annot =True, linewidths=0.5,linecolor="green",fmt=".2f",ax=ax)
plt.show()
data.head()
"""
**pair plot**
"""
sns.pairplot(data)
plt.show()