"""
<h2> Basic Information </h2>
The above data is About the <b>suicide rates in India</b>. The data is **stratified based on the eductation status, means adopted and professional profile**. The data recorded is observed from the time duration 2001-2012.
"""
# 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

import numpy as np # linear algebra
import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)
import matplotlib.pyplot as plt
import seaborn as sns
import warnings
warnings.filterwarnings('ignore') 
sns.set()
# Input data files are available in the read-only "../input/" directory
# For example, running this (by clicking run or pressing Shift+Enter) will list all files under the input directory

import os
for dirname, _, filenames in os.walk('/kaggle/input'):
    for filename in filenames:
        print(os.path.join(dirname, filename))

# You can write up to 20GB to the current directory (/kaggle/working/) that gets preserved as output when you create a version using "Save & Run All" 
# You can also write temporary files to /kaggle/temp/, but they won't be saved outside of the current session
#reading the data 
data=pd.read_csv('/kaggle/input/suicides-in-india/Suicides in India 2001-2012.csv')
data.head()
data.replace('A & N Islands (Ut)', 'A & N Islands', inplace=True)
data.replace('Chandigarh (Ut)', 'Chandigarh', inplace=True)
data.replace('D & N Haveli (Ut)', 'D & N Haveli', inplace=True)
data.replace('Daman & Diu (Ut)', 'Daman & Diu', inplace=True)
data.replace('Lakshadweep (Ut)', 'Lakshadweep', inplace=True)
data.replace('Delhi (Ut)', 'Delhi', inplace=True)
data.replace('Bankruptcy or Sudden change in Economic','Bankruptcy or Sudden change in Economic Status', inplace=True)
data.replace('By Other means (please specify)', 'By Other means', inplace=True)
data.replace('Not having Children(Barrenness/Impotency','Not having Children (Barrenness/Impotency)', inplace=True)
data.sample(5)
"""
Now Let us examine the number of cases reported gender wise
"""
print(data.Gender.value_counts())
gen=data.groupby('Gender').sum()['Total'].plot(kind = "bar",figsize=(5,4),title='Segregation by gender',color='blue')
plt.savefig('genderwise.png')
gen.set_xlabel('Gender')
gen.set_ylabel('Count\n')
sns.set_palette('Set2');
"""
From the above graph it can be infered that there are more case of males comitting suicide documented as compared to females during the time period 2001-2012 <br>
Let us further explore the data on the leading causes of suicide based on gender
"""
fem_gender=data[data['Gender']=='Female']
fem_causes=fem_gender[fem_gender['Type_code']=='Causes']
plt_type = fem_causes.groupby('Type').sum()['Total']
sort_df = plt_type.sort_values(ascending = True)
figure = sort_df.plot(kind = 'barh', figsize = (10,6), title = 'Causes of suicide in Female' + '\n', width = 0.75)
figure.set_ylabel('Cause\n')
figure.set_xlabel('\n' + 'count' )

male_gender=data[data['Gender']=='Male']
male_causes=male_gender[male_gender['Type_code']=='Causes']
plt_type = male_causes.groupby('Type').sum()['Total']
sort_df = plt_type.sort_values(ascending = True)
figure = sort_df.plot(kind = 'barh', figsize = (10,6), title = 'Causes of suicide in Male' + '\n', width = 0.75)
figure.set_xlabel('\n' + 'count' )
figure.set_ylabel('Cause\n')
"""
from the above two graphs it can be infered that Family related problems is the leading cause of suicide in both the genders.<br>
Next let us explore the cases of suicides based on age groups
"""
print(data.Age_group.value_counts())
gen=data.groupby('Age_group').sum()['Total'].plot(kind = "bar",figsize=(4,5),title='Segregation by Age group',color='black')
gen.set_xlabel('Age')
gen.set_ylabel('Count\n')
sns.set_palette('Set2');
"""
From the above graph we can infer that induviduals in the age group 15-29 and 30-44 are more prone to suicide. Sadly there's a small population of elderly and children between 0 to 14 comitting suicide.
"""
elderly = data[data['Age_group']== '60+']
causes=elderly[elderly['Type_code']=='Causes']
plt_type=causes.groupby('Type').sum()['Total']
sort_df = plt_type.sort_values(ascending = True)
figure = sort_df.plot(kind ='barh', figsize = (10,6), title = 'Causes in Elderly' + '\n', width = 0.75)
figure.set_ylabel('Cause\n')
figure.set_xlabel('\n' + 'count' )

children = data[data['Age_group']== '0-14']
causes=children[children['Type_code']=='Causes']
plt_type=causes.groupby('Type').sum()['Total']
sort_df = plt_type.sort_values(ascending = True)
figure = sort_df.plot(kind ='barh', figsize = (10,6), title = 'Causes in children' + '\n', width = 0.75)
figure.set_ylabel('Cause\n')
figure.set_xlabel('\n' + 'count' )
"""
From the above chart it can be infered that prolonged illness, are the main cause of suicides in the elderly and in children though lot of cases were recorded for unknown causes, It can bee seen that family problem and failure in examination is leading causes.
"""
"""
Since India is a family centered society, I would like to explore how Impotency,Family related issues,Divorce,Non settlement of marriage affect genderwise
"""
#suicide related to family problems grouped by gender
causes = data[data['Type'].isin(['Not having Children (Barrenness/Impotency)', 'Family Problem','Divorce','Cancellation/Non-Settlement of Marriage'])]
affect=causes.groupby('Gender').sum()['Total'].plot(kind = "bar",figsize=(4,5),title='Cases of suicide due to family related issues',color='black')
"""
let us explore the trends in suicide related to family related issues in females
"""
causes = data[data['Type'].isin(['Not having Children (Barrenness/Impotency)', 'Family Problem','Divorce','Cancellation/Non-Settlement of Marriage'])]
causes1=children[children['Gender']=='Female']
affect=causes1.groupby('Year').sum()['Total'].plot(kind="line",figsize=(4,5),title='Number of cases in Female gender due to family related issues',color='black')
"""
It is positive to see that the number of cases have been declining 2010-2012
"""
"""
On the other side of the spectrum, let us explore the suicide related to Financial issues, careers and reputation grouped by gender.
"""
#financial related problem grouped by gender
causes = data[data['Type'].isin(['Property Dispute', 'Fall In Social Reputation','Professional/Career Problem','Unemployment','Poverty'])]
affect=causes.groupby('Gender').sum()['Total'].plot(kind="bar",figsize=(4,5),title='Cases of suicide due to societal factors',color='black')
"""
It can be observed that male fall victim to profession related issues let us see  the trends in suicide related to profession related issues in males,let us plot how the cases have been varied over the years
"""
causes = data[data['Type'].isin(['Property Dispute', 'Fall In Social Reputation','Professional/Career Problem','Unemployment','Poverty'])]
causes1=causes[causes['Gender']=='Male']
affect=causes1.groupby('Year').sum()['Total'].plot(kind = "line",figsize=(4,5),title='Cases of suicide due to socieital factors',color='black')

"""
It is positive to see that the number of cases have been declining 2010-2012
"""
"""
Let us also take look into another issue, How physical and mental illness affect or impact lives.
"""
causes = data[data['Type'].isin(['Illness (Aids/STD)','Other Prolonged Illness'])]
affect=causes.groupby('Year').sum()['Total'].plot(kind = "line",figsize=(4,5),title='Mental Health Stigma related to illness',color='black')

causes = data[data['Type']== 'Insanity/Mental Illness']
affect=causes.groupby('Year').sum()['Total'].plot(kind = "line",figsize=(4,5),title='Suicide trends based on mental illness',color='black')
"""
**CONCLUSIONS**


1.   Family Related problem are cause of death in both the genders
2.   Prolonged illness and education related issues have been the leading cause of suicide in elderly and in Kids respectively
3.   Men are more likely be victims of financial related issues 
4.   Women are more likely victims of family related issues
5.  Despite the alarming causes there has been steady decline of cases reported for the above two points
6.   There has been a decline in the amount of suicide due to illness 
7.   There has been a sharp incline and a slow in the cases of suicide due mental illness
"""