The suicides (part 2) (to be completed)
- Jamie (Trang Nguyen)

- Sep 23, 2020
- 2 min read
Warning:
This blog may use inappropriate language (dark jokes) to people who are sensitive to the dead. Please consider skipping this blog if your history has something related to suicidal events.
You might find this blog written in a sarcastic tone, but I would like to emphasize that I don't mean to hurt others' feelings or poke fun at their wound.In the previous blog, the cleansing stage had already finished. Let's assume that the data is now clear and ready for the visualization. This blog will continue to observe the suicide rate in general and its correlation with other socio-economic aspects namely GDP (how richness affects suicide rate), gender (how feminism affects suicide rate), generation (in which generation people win the desperation contest), et cetera.
General
The most-used function within this blog is df.groupby(), which split data into groups under some criteria indicated inside the parentheses, and df.agg(), which apply aggregation across one or more columns.
For example, to see how the suicide rate develops through the years, it needs to group by year and calculate total suicides cases of every country in this particular year.
data.groupby(['year']).agg({'suicides_no':'sum'})If I were (actually, I am) a lazy ass, I would plot it right away like this:
data.groupby(['year']).agg({'suicides_no':'sum'}).plot(kind='line', color='darkred')The outcome will be something like this:

"Chart name?" - "No..."
"Axis labels?" - "What the heck are these?"
"Then what if you need to convince a business partner to cooperate with your company, would you confidently export this naked chart, solemnly put it in a pitching presentation slide, and send it right away to your boss with your heart full of faith that you are helping your company win a precious deal and initiate a happy corporation with the counterpart?" - "At least, I pick the plot kind and change the default color."
matplotlib was imported for a reason. Hereafter is the code and its outcome
year_sui=data.groupby(['year']).agg({'suicides_no':'sum'})
year_sui.plot(color='darkred')
plt.title('Total No. Of Suicides Per Year From 1985 To 2016')
plt.ylabel('No. Suicides')
plt.xlabel('Year')
plt.xlim((data.year.min() -1 ), (data.year.max()+1))
plt.show()

Comments