In [1]:
import pandas as pd
In [71]:
df = pd.read_csv('suicide_history.csv')
In [72]:
df.columns
Out[72]:
Index(['Date', 'Age', 'Gender', 'Profession', 'Methodology', 'Reason', 'Time',
'District', 'Source'],
dtype='object')
In [73]:
df = df.sort('Age')
C:\Anaconda3\lib\site-packages\ipykernel\__main__.py:1: FutureWarning: sort(columns=....) is deprecated, use sort_values(by=.....)
if __name__ == '__main__':
In [74]:
df['Reason'] = [x.lower() for x in df['Reason']]
df = df[(df['Reason'] != 'not given') & (df['Reason'] != '-') & (df['Reason'] != 'not known') & (df['Reason'] != 'unknown')]
In [75]:
# Category 8-12
df_8_12 = df[(df['Age'] >= 8) & (df['Age'] <= 12)]
In [76]:
# Category 13-18
df_13_18 = df[(df['Age'] >= 13) & (df['Age'] <= 18)]
In [77]:
# Category 19-26
df_19_26 = df[(df['Age'] >= 19) & (df['Age'] <= 26)]
In [78]:
# Category 27-35
df_27_35 = df[(df['Age'] >= 27) & (df['Age'] <= 35)]
In [79]:
# Category 36-50
df_36_50 = df[(df['Age'] >= 36) & (df['Age'] <= 50)]
In [80]:
# Category 51-80
df_51_80 = df[(df['Age'] >= 51) & (df['Age'] <= 80)]
In [81]:
# Category 81-103
df_81_103 = df[(df['Age'] >= 81) & (df['Age'] <= 103)]
In [82]:
df_81_103
Out[82]:
Date
Age
Gender
Profession
Methodology
Reason
Time
District
Source
432
2/7/2012
85
Female
not given
Hanging
family feud
5:00:00
Shatkhira
http://archive.thedailystar.net/newDesign/news...
795
9/9/2013
103
Male
not given
Hanging
family feud
-
Joypurhat
http://archive.thedailystar.net/beta2/news/sni...
In [83]:
df.shape
Out[83]:
(673, 9)
In [91]:
df_8_12['Age'] = ['8 to 12' for i in range(df_8_12.shape[0])]
df_13_18['Age'] = ['13 to 18' for i in range(df_13_18.shape[0])]
df_19_26['Age'] = ['19 to 26' for i in range(df_19_26.shape[0])]
df_27_35['Age'] = ['27 to 35' for i in range(df_27_35.shape[0])]
df_36_50['Age'] = ['36 to 50' for i in range(df_36_50.shape[0])]
df_51_80['Age'] = ['51 to 80' for i in range(df_51_80.shape[0])]
df_81_103['Age'] = ['81 to 103' for i in range(df_81_103.shape[0])]
C:\Anaconda3\lib\site-packages\ipykernel\__main__.py:1: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/indexing.html#indexing-view-versus-copy
if __name__ == '__main__':
C:\Anaconda3\lib\site-packages\ipykernel\__main__.py:2: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/indexing.html#indexing-view-versus-copy
from ipykernel import kernelapp as app
C:\Anaconda3\lib\site-packages\ipykernel\__main__.py:3: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/indexing.html#indexing-view-versus-copy
app.launch_new_instance()
C:\Anaconda3\lib\site-packages\ipykernel\__main__.py:4: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/indexing.html#indexing-view-versus-copy
C:\Anaconda3\lib\site-packages\ipykernel\__main__.py:5: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/indexing.html#indexing-view-versus-copy
C:\Anaconda3\lib\site-packages\ipykernel\__main__.py:6: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/indexing.html#indexing-view-versus-copy
C:\Anaconda3\lib\site-packages\ipykernel\__main__.py:7: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/indexing.html#indexing-view-versus-copy
In [94]:
dfs = pd.concat(frames)
In [93]:
frames = [df_8_12, df_13_18, df_19_26, df_27_35, df_36_50, df_51_80, df_81_103]
In [95]:
dfs
Out[95]:
Date
Age
Gender
Profession
Methodology
Reason
Time
District
Source
472
3/30/2012
8 to 12
Male
Student
Hanging
family feud
20:30:00
Dhaka
http://archive.thedailystar.net/newDesign/news...
627
9/30/2012
8 to 12
Female
Student
Poison
allegation
23:30:00
Jessore
http://archive.thedailystar.net/newDesign/news...
188
2/8/2011
8 to 12
Female
student
Poison
family feud
not given
Shatkhira
http://archive.thedailystar.net/newDesign/news...
636
10/20/2012
8 to 12
Female
not given
Hanging
physical illness
not given
Dhaka
http://archive.thedailystar.net/newDesign/news...
230
4/5/2011
8 to 12
Male
student
Poison
family feud
not given
Shatkhira
http://archive.thedailystar.net/newDesign/news...
670
12/24/2012
8 to 12
Female
Student
Hanging
family feud
not given
Dhaka
http://archive.thedailystar.net/newDesign/news...
592
9/4/2012
8 to 12
Male
Student
Hanging
family feud
0:30:00
Dhaka
http://archive.thedailystar.net/newDesign/news...
179
1/25/2011
8 to 12
Female
student
Poison
failing in exam
not given
Shatkhira
http://archive.thedailystar.net/newDesign/news...
763
7/24/2013
8 to 12
Female
Student
Hanging
family feud
Evening
Magura
http://archive.thedailystar.net/beta2/news/sni...
478
4/3/2012
8 to 12
Male
Student
Poison
family feud
Noon
Rangpur
http://archive.thedailystar.net/newDesign/news...
388
11/27/2011
8 to 12
Male
student
Hanging
family feud
morning
Manikganj
http://archive.thedailystar.net/newDesign/news...
359
10/3/2011
8 to 12
Female
student
Hanging
family feud
not given
Manikganj
http://archive.thedailystar.net/newDesign/news...
626
9/29/2012
8 to 12
Female
not given
Hanging
family feud
Night
Pabna
http://archive.thedailystar.net/newDesign/news...
962
10/23/2014
8 to 12
Male
not given
Hanging
imitating suicide
noon
Sunamganj
http://www.thedailystar.net/boy-dies-while-imi...
306
7/19/2011
8 to 12
Female
student
Hanging
eve teasing
20:00:00
Dhaka
http://archive.thedailystar.net/newDesign/news...
529
6/9/2012
8 to 12
Female
Student
Hanging
family feud
21:00:00
Thakurgaon
http://archive.thedailystar.net/newDesign/news...
14
2/3/2010
8 to 12
Female
Student
Hanging
eve teasing
Afternoon
Pabna
http://archive.thedailystar.net/newDesign/news...
75
7/19/2010
8 to 12
Female
Student
Poison
family feud
Night
Lalmonirhat
http://archive.thedailystar.net/newDesign/news...
688
2/8/2013
8 to 12
Female
Student
hanging
physical illness; family feud
not given
Dhaka
http://archive.thedailystar.net/newDesign/news...
897
5/31/2014
8 to 12
Female
not given
Hanging
mental disorder
Night
Chittagong
http://www.thedailystar.net/newsarchive/news-i...
679
1/10/2013
8 to 12
Female
student
hanging
family feud
Afternoon
Pabna
http://archive.thedailystar.net/newDesign/news...
696
3/6/2013
8 to 12
Female
not given
hanging
family feud
Morning
Bogra
http://archive.thedailystar.net/beta2/news/min...
327
8/16/2011
8 to 12
Female
not given
Posion
family feud
night
Kushtia
http://archive.thedailystar.net/newDesign/news...
640
10/22/2012
8 to 12
Male
Student
Hanging
family feud
Night
Dhaka
http://archive.thedailystar.net/newDesign/news...
913
6/23/2014
8 to 12
Male
Student
Hanging
family feud
Afternoon
Magura
http://www.thedailystar.net/newsarchive/snippe...
590
8/27/2012
13 to 18
Female
Student
Hanging
forced marriage
not given
Barguna
http://archive.thedailystar.net/newDesign/news...
674
12/28/2012
13 to 18
Female
Student
Hanging
academic problem
Evening
Jessore
http://archive.thedailystar.net/newDesign/news...
253
4/22/2011
13 to 18
Female
slum residant
Poison
family feud
night
Dhaka
http://archive.thedailystar.net/newDesign/news...
242
4/17/2011
13 to 18
Female
student
Poison
family feud
morning
Shatkhira
http://archive.thedailystar.net/newDesign/news...
90
8/11/2010
13 to 18
Female
not given
Poison
family feud
Morning
Khagrachhari
http://archive.thedailystar.net/newDesign/news...
...
...
...
...
...
...
...
...
...
...
272
6/4/2011
36 to 50
Male
former member of Gopalganj Union Parishad
Jumped in front of train
losing election
morning
Dinajpur
http://archive.thedailystar.net/newDesign/news...
876
4/2/2014
51 to 80
Male
Farmer
Hanging
quarrel with spouse
Evening
Chuadanga
http://www.thedailystar.net/newsarchive/snippe...
316
7/29/2011
51 to 80
Male
Policeman
Hanging
illness
5:00:00
Chittagong
http://archive.thedailystar.net/newDesign/news...
880
4/16/2014
51 to 80
Male
Not mentioned
Hanging
family feud
Night
Thakurgaon
http://www.thedailystar.net/newsarchive/snippe...
939
9/1/2014
51 to 80
Male
Owner of Afsar Group of Industries
Shooting
business loss
18:00:00
Dhaka
http://www.thedailystar.net/couple-found-dead-...
496
4/27/2012
51 to 80
Male
not given
Poison
family feud
Morning
Shatkhira
http://archive.thedailystar.net/newDesign/news...
233
4/10/2011
51 to 80
Male
police constable
Poison
family feud
17:00:00
Shatkhira
http://archive.thedailystar.net/newDesign/news...
503
5/5/2012
51 to 80
Male
Tea vendor
Hanging
personal problem
18:15:00
Chittagong
http://archive.thedailystar.net/newDesign/news...
485
4/9/2012
51 to 80
Male
not given
Poison
family feud
1899-12-30 00:00:00
Dinajpur
http://archive.thedailystar.net/newDesign/news...
424
2/2/2012
51 to 80
Male
Stock broker
Hanging
personal problem
8:30:00
Chittagong
http://archive.thedailystar.net/newDesign/news...
888
5/3/2014
51 to 80
Male
Journalist
Hanging
family feud
0:30:00
Patuakhali
http://www.thedailystar.net/newsarchive/amar-d...
308
7/21/2011
51 to 80
Male
not given
Hanging
family feud
7:30:00
Shatkhira
http://archive.thedailystar.net/newDesign/news...
547
7/12/2012
51 to 80
Male
Joint Secretary (public Administration Ministry)
Hanging
illness
Morning
Dhaka
http://archive.thedailystar.net/newDesign/news...
452
3/13/2012
51 to 80
Male
Ex-BCIC official
Hanging
medical problems
Morning
Dhaka
http://archive.thedailystar.net/newDesign/news...
817
11/13/2013
51 to 80
Male
not given
Poison
family feud
Morning
Chuadanga
http://archive.thedailystar.net/beta2/news/sni...
486
4/10/2012
51 to 80
Male
not given
Hanging
family feud
1899-12-30 00:00:00
Dinajpur
http://archive.thedailystar.net/newDesign/news...
108
8/29/2010
51 to 80
Female
not given
Hanging
family feud
Morning
Thakurgaon
http://archive.thedailystar.net/newDesign/news...
815
11/8/2013
51 to 80
Male
not given
Hanging
mental disorder
21:00:00
Jessore
http://archive.thedailystar.net/beta2/news/sni...
865
3/16/2014
51 to 80
Female
Elderly
Hanging
financial problem
Morning
Jamalpur
http://www.thedailystar.net/snippets-15870
455
3/17/2012
51 to 80
Male
Freedom fighter
Poison
family feud
-
Jessore
http://archive.thedailystar.net/newDesign/news...
303
7/13/2011
51 to 80
Male
not given
Poison
family feud
not given
Shatkhira
http://archive.thedailystar.net/newDesign/news...
446
3/3/2012
51 to 80
Male
not given
Hanging
family feud
Night
Shatkhira
http://archive.thedailystar.net/newDesign/news...
471
3/30/2012
51 to 80
Male
Doctor
Jumping off
medical problems
Afternoon
Dhaka
http://archive.thedailystar.net/newDesign/news...
252
4/20/2011
51 to 80
Female
not given
Hanging
family feud
night
Jhenidah
http://archive.thedailystar.net/newDesign/news...
392
12/3/2011
51 to 80
Male
not given
Hanging
family feud
5:30:00
Shatkhira
http://archive.thedailystar.net/newDesign/news...
26
2/27/2010
51 to 80
Male
not given
Hanging
family feud
Night
Kushtia
http://archive.thedailystar.net/newDesign/news...
9
1/28/2010
51 to 80
Female
Student
Poison
family feud
Afternoon
Shatkhira
http://archive.thedailystar.net/newDesign/news...
480
4/7/2012
51 to 80
Male
not given
Poison
family feud
-
Narail
http://archive.thedailystar.net/newDesign/news...
432
2/7/2012
81 to 103
Female
not given
Hanging
family feud
5:00:00
Shatkhira
http://archive.thedailystar.net/newDesign/news...
795
9/9/2013
81 to 103
Male
not given
Hanging
family feud
-
Joypurhat
http://archive.thedailystar.net/beta2/news/sni...
673 rows × 9 columns
In [96]:
dfs.to_csv('suicide_ordinal_csv')
In [ ]:
Content source: manashmndl/Kolpokoushol
Similar notebooks: