In [ ]:
In [1]:
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
/var/folders/gc/0752xrm56pnf0r0dsrn5370c0000gr/T/ipykernel_71471/555797462.py:1: DeprecationWarning: Pyarrow will become a required dependency of pandas in the next major release of pandas (pandas 3.0), (to allow more performant data types, such as the Arrow string type, and better interoperability with other libraries) but was not found to be installed on your system. If this would cause problems for you, please provide us feedback at https://github.com/pandas-dev/pandas/issues/54466 import pandas as pd
In [2]:
#Loading the dataset
data = pd.read_csv("Death_rates_for_suicide__by_sex__race__Hispanic_origin__and_age__United_States.csv")
In [3]:
# Filter the dataset to include males who are Asian or Pacific Islander Male Data or African American between the ages of 25-44 years and the years 1950 and 1984
Asian_or_Pacific_Islander_Male_Data = data[(data['STUB_LABEL'].str.contains('Male: Asian or Pacific Islander')) &
(data['YEAR'].between(1985, 2018))]
# Display the filtered dataset including the INDICATOR, UNIT, AGE, YEAR, and ESTIMATE columns
Asian_or_Pacific_Islander_Male_Data[['INDICATOR', 'UNIT', 'STUB_LABEL', 'AGE', 'YEAR', 'ESTIMATE']]
Out[3]:
INDICATOR | UNIT | STUB_LABEL | AGE | YEAR | ESTIMATE | |
---|---|---|---|---|---|---|
554 | Death rates for suicide | Deaths per 100,000 resident population, crude | Male: Asian or Pacific Islander: 15-24 years | 15-24 years | 1985 | 14.2 |
555 | Death rates for suicide | Deaths per 100,000 resident population, crude | Male: Asian or Pacific Islander: 15-24 years | 15-24 years | 1986 | NaN |
556 | Death rates for suicide | Deaths per 100,000 resident population, crude | Male: Asian or Pacific Islander: 15-24 years | 15-24 years | 1987 | NaN |
557 | Death rates for suicide | Deaths per 100,000 resident population, crude | Male: Asian or Pacific Islander: 15-24 years | 15-24 years | 1988 | 8.5 |
558 | Death rates for suicide | Deaths per 100,000 resident population, crude | Male: Asian or Pacific Islander: 15-24 years | 15-24 years | 1989 | 11.6 |
... | ... | ... | ... | ... | ... | ... |
667 | Death rates for suicide | Deaths per 100,000 resident population, crude | Male: Asian or Pacific Islander: 45-64 years | 45-64 years | 2014 | 12.1 |
668 | Death rates for suicide | Deaths per 100,000 resident population, crude | Male: Asian or Pacific Islander: 45-64 years | 45-64 years | 2015 | 10.9 |
669 | Death rates for suicide | Deaths per 100,000 resident population, crude | Male: Asian or Pacific Islander: 45-64 years | 45-64 years | 2016 | 11.8 |
670 | Death rates for suicide | Deaths per 100,000 resident population, crude | Male: Asian or Pacific Islander: 45-64 years | 45-64 years | 2017 | 11.0 |
671 | Death rates for suicide | Deaths per 100,000 resident population, crude | Male: Asian or Pacific Islander: 45-64 years | 45-64 years | 2018 | 12.2 |
102 rows × 6 columns
In [4]:
Asian_or_Pacific_Islander_Female_Data = data[(data['STUB_LABEL'].str.contains('Female: Asian or Pacific Islander')) &
(data['YEAR'].between(1985, 2018))]
Asian_or_Pacific_Islander_Female_Data[['INDICATOR', 'UNIT', 'STUB_LABEL', 'AGE', 'YEAR', 'ESTIMATE']]
Out[4]:
INDICATOR | UNIT | STUB_LABEL | AGE | YEAR | ESTIMATE | |
---|---|---|---|---|---|---|
1058 | Death rates for suicide | Deaths per 100,000 resident population, crude | Female: Asian or Pacific Islander: 15-24 years | 15-24 years | 1985 | 5.8 |
1059 | Death rates for suicide | Deaths per 100,000 resident population, crude | Female: Asian or Pacific Islander: 15-24 years | 15-24 years | 1986 | NaN |
1060 | Death rates for suicide | Deaths per 100,000 resident population, crude | Female: Asian or Pacific Islander: 15-24 years | 15-24 years | 1987 | NaN |
1061 | Death rates for suicide | Deaths per 100,000 resident population, crude | Female: Asian or Pacific Islander: 15-24 years | 15-24 years | 1988 | NaN |
1062 | Death rates for suicide | Deaths per 100,000 resident population, crude | Female: Asian or Pacific Islander: 15-24 years | 15-24 years | 1989 | 4.2 |
... | ... | ... | ... | ... | ... | ... |
1171 | Death rates for suicide | Deaths per 100,000 resident population, crude | Female: Asian or Pacific Islander: 45-64 years | 45-64 years | 2014 | 4.2 |
1172 | Death rates for suicide | Deaths per 100,000 resident population, crude | Female: Asian or Pacific Islander: 45-64 years | 45-64 years | 2015 | 5.2 |
1173 | Death rates for suicide | Deaths per 100,000 resident population, crude | Female: Asian or Pacific Islander: 45-64 years | 45-64 years | 2016 | 4.5 |
1174 | Death rates for suicide | Deaths per 100,000 resident population, crude | Female: Asian or Pacific Islander: 45-64 years | 45-64 years | 2017 | 4.2 |
1175 | Death rates for suicide | Deaths per 100,000 resident population, crude | Female: Asian or Pacific Islander: 45-64 years | 45-64 years | 2018 | 4.8 |
102 rows × 6 columns
What the code below does:¶
It visualizes the suicide estimates over time for Asian or Pacific Islander males and females, by creating a single plot showing all the suicide estimates over time, categorized by age.
In [5]:
# Create a single plot
plt.figure(figsize=(12, 8))
# Define colors for each age category
colors = ['blue', 'green', 'red', 'orange', 'purple', 'cyan', 'magenta', 'yellow', 'lime', 'pink']
# Plot line plots for each age category for Asian or Pacific Islander Males
for i, age_category in enumerate(['15-24 years', '25-44 years', '45-64 years', '65-74 years', '75-84 years']):
# Filter data for Asian or Pacific Islander Males of the current age category
male_data = Asian_or_Pacific_Islander_Male_Data[Asian_or_Pacific_Islander_Male_Data['AGE'] == age_category]
# Plot line plot for Asian or Pacific Islander Males of the current age category with a different color
plt.plot(male_data['YEAR'], male_data['ESTIMATE'], color=colors[i], marker='o', label=f'Asian or Pacific Islander Males ({age_category})')
# Plot line plots for each age category for Asian or Pacific Islander Females
for i, age_category in enumerate(['15-24 years', '25-44 years', '45-64 years', '65-74 years', '75-84 years']):
# Filter data for Asian or Pacific Islander Females of the current age category
female_data = Asian_or_Pacific_Islander_Female_Data[Asian_or_Pacific_Islander_Female_Data['AGE'] == age_category]
# Plot line plot for Asian or Pacific Islander Females of the current age category with a different color
plt.plot(female_data['YEAR'], female_data['ESTIMATE'], color=colors[i+len(colors)//2], marker='o', linestyle='--', label=f'Asian or Pacific Islander Females ({age_category})')
# Set titles and labels
plt.title('Suicide Estimates Over Time for Asian or Pacific Islander Males and Females by Age Category')
plt.xlabel('Year')
plt.ylabel('Suicide Estimate (% per 100,000 resident population)')
# Add legend
plt.legend()
# Show the plot
plt.grid(True)
plt.tight_layout()
plt.show()