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_70616/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 [ ]:
 
In [3]:
# Filter the dataset to include males who are American Indian or Alaska Native or African American between the ages of 25-44 years and the years 1950 and 1984
American_Indian_or_Alaska_Native_Male_Data = data[(data['STUB_LABEL'].str.contains('Male: American Indian or Alaska Native')) & 
                     (data['YEAR'].between(1985, 2018))]

# Display the filtered dataset including the INDICATOR, UNIT, AGE, YEAR, and ESTIMATE columns
American_Indian_or_Alaska_Native_Male_Data[['INDICATOR', 'UNIT', 'STUB_LABEL', 'AGE', 'YEAR', 'ESTIMATE']]
Out[3]:
INDICATOR UNIT STUB_LABEL AGE YEAR ESTIMATE
429 Death rates for suicide Deaths per 100,000 resident population, crude Male: American Indian or Alaska Native: 15-24 ... 15-24 years 1985 42.0
430 Death rates for suicide Deaths per 100,000 resident population, crude Male: American Indian or Alaska Native: 15-24 ... 15-24 years 1986 NaN
431 Death rates for suicide Deaths per 100,000 resident population, crude Male: American Indian or Alaska Native: 15-24 ... 15-24 years 1987 NaN
432 Death rates for suicide Deaths per 100,000 resident population, crude Male: American Indian or Alaska Native: 15-24 ... 15-24 years 1988 41.8
433 Death rates for suicide Deaths per 100,000 resident population, crude Male: American Indian or Alaska Native: 15-24 ... 15-24 years 1989 43.7
... ... ... ... ... ... ...
541 Death rates for suicide Deaths per 100,000 resident population, crude Male: American Indian or Alaska Native: 45-64 ... 45-64 years 2013 18.3
542 Death rates for suicide Deaths per 100,000 resident population, crude Male: American Indian or Alaska Native: 45-64 ... 45-64 years 2014 15.1
543 Death rates for suicide Deaths per 100,000 resident population, crude Male: American Indian or Alaska Native: 45-64 ... 45-64 years 2015 20.8
544 Death rates for suicide Deaths per 100,000 resident population, crude Male: American Indian or Alaska Native: 45-64 ... 45-64 years 2016 19.8
545 Death rates for suicide Deaths per 100,000 resident population, crude Male: American Indian or Alaska Native: 45-64 ... 45-64 years 2017 19.7

101 rows × 6 columns

In [4]:
American_Indian_or_Alaska_Native_Female_Data = data[(data['STUB_LABEL'].str.contains('Female: American Indian or Alaska Native')) & 
                     (data['AGE'] == '25-44 years') & 
                     (data['YEAR'].between(1985, 2018))]

American_Indian_or_Alaska_Native_Female_Data[['INDICATOR', 'UNIT', 'STUB_LABEL', 'AGE', 'YEAR', 'ESTIMATE']]
Out[4]:
INDICATOR UNIT STUB_LABEL AGE YEAR ESTIMATE
975 Death rates for suicide Deaths per 100,000 resident population, crude Female: American Indian or Alaska Native: 25-4... 25-44 years 1985 NaN
976 Death rates for suicide Deaths per 100,000 resident population, crude Female: American Indian or Alaska Native: 25-4... 25-44 years 1986 NaN
977 Death rates for suicide Deaths per 100,000 resident population, crude Female: American Indian or Alaska Native: 25-4... 25-44 years 1987 NaN
978 Death rates for suicide Deaths per 100,000 resident population, crude Female: American Indian or Alaska Native: 25-4... 25-44 years 1988 6.9
979 Death rates for suicide Deaths per 100,000 resident population, crude Female: American Indian or Alaska Native: 25-4... 25-44 years 1989 NaN
980 Death rates for suicide Deaths per 100,000 resident population, crude Female: American Indian or Alaska Native: 25-4... 25-44 years 1990 NaN
981 Death rates for suicide Deaths per 100,000 resident population, crude Female: American Indian or Alaska Native: 25-4... 25-44 years 1991 5.8
982 Death rates for suicide Deaths per 100,000 resident population, crude Female: American Indian or Alaska Native: 25-4... 25-44 years 1992 5.6
983 Death rates for suicide Deaths per 100,000 resident population, crude Female: American Indian or Alaska Native: 25-4... 25-44 years 1993 6.6
984 Death rates for suicide Deaths per 100,000 resident population, crude Female: American Indian or Alaska Native: 25-4... 25-44 years 1994 NaN
985 Death rates for suicide Deaths per 100,000 resident population, crude Female: American Indian or Alaska Native: 25-4... 25-44 years 1995 6.4
986 Death rates for suicide Deaths per 100,000 resident population, crude Female: American Indian or Alaska Native: 25-4... 25-44 years 1996 8.0
987 Death rates for suicide Deaths per 100,000 resident population, crude Female: American Indian or Alaska Native: 25-4... 25-44 years 1997 5.6
988 Death rates for suicide Deaths per 100,000 resident population, crude Female: American Indian or Alaska Native: 25-4... 25-44 years 1998 6.8
989 Death rates for suicide Deaths per 100,000 resident population, crude Female: American Indian or Alaska Native: 25-4... 25-44 years 1999 6.8
990 Death rates for suicide Deaths per 100,000 resident population, crude Female: American Indian or Alaska Native: 25-4... 25-44 years 2000 7.2
991 Death rates for suicide Deaths per 100,000 resident population, crude Female: American Indian or Alaska Native: 25-4... 25-44 years 2001 6.0
992 Death rates for suicide Deaths per 100,000 resident population, crude Female: American Indian or Alaska Native: 25-4... 25-44 years 2002 5.4
993 Death rates for suicide Deaths per 100,000 resident population, crude Female: American Indian or Alaska Native: 25-4... 25-44 years 2003 4.3
994 Death rates for suicide Deaths per 100,000 resident population, crude Female: American Indian or Alaska Native: 25-4... 25-44 years 2004 8.9
995 Death rates for suicide Deaths per 100,000 resident population, crude Female: American Indian or Alaska Native: 25-4... 25-44 years 2005 6.6
996 Death rates for suicide Deaths per 100,000 resident population, crude Female: American Indian or Alaska Native: 25-4... 25-44 years 2006 6.9
997 Death rates for suicide Deaths per 100,000 resident population, crude Female: American Indian or Alaska Native: 25-4... 25-44 years 2007 5.8
998 Death rates for suicide Deaths per 100,000 resident population, crude Female: American Indian or Alaska Native: 25-4... 25-44 years 2008 6.2
999 Death rates for suicide Deaths per 100,000 resident population, crude Female: American Indian or Alaska Native: 25-4... 25-44 years 2009 7.5
1000 Death rates for suicide Deaths per 100,000 resident population, crude Female: American Indian or Alaska Native: 25-4... 25-44 years 2010 7.4
1001 Death rates for suicide Deaths per 100,000 resident population, crude Female: American Indian or Alaska Native: 25-4... 25-44 years 2011 7.8
1002 Death rates for suicide Deaths per 100,000 resident population, crude Female: American Indian or Alaska Native: 25-4... 25-44 years 2012 6.6
1003 Death rates for suicide Deaths per 100,000 resident population, crude Female: American Indian or Alaska Native: 25-4... 25-44 years 2013 7.5
1004 Death rates for suicide Deaths per 100,000 resident population, crude Female: American Indian or Alaska Native: 25-4... 25-44 years 2014 9.7
1005 Death rates for suicide Deaths per 100,000 resident population, crude Female: American Indian or Alaska Native: 25-4... 25-44 years 2015 8.8
1006 Death rates for suicide Deaths per 100,000 resident population, crude Female: American Indian or Alaska Native: 25-4... 25-44 years 2016 10.7
1007 Death rates for suicide Deaths per 100,000 resident population, crude Female: American Indian or Alaska Native: 25-4... 25-44 years 2017 12.1
1008 Death rates for suicide Deaths per 100,000 resident population, crude Female: American Indian or Alaska Native: 25-4... 25-44 years 2018 10.8

What the code below does:¶

It visualizes the suicide estimates over time for American Indian or Alaska Native 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 American Indian or Alaska Native 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 American Indian or Alaska Native Males of the current age category
    male_data = American_Indian_or_Alaska_Native_Male_Data[American_Indian_or_Alaska_Native_Male_Data['AGE'] == age_category]
    
    # Plot line plot for American Indian or Alaska Native 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'American Indian or Alaska Native Males ({age_category})')

# Plot line plots for each age category for American Indian or Alaska Native 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 American Indian or Alaska Native Females of the current age category
    female_data = American_Indian_or_Alaska_Native_Female_Data[American_Indian_or_Alaska_Native_Female_Data['AGE'] == age_category]
    
    # Plot line plot for American Indian or Alaska Native 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'American Indian or Alaska Native Females ({age_category})')

# Set titles and labels
plt.title('Suicide Estimates Over Time for American Indian or Alaska Native 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()
No description has been provided for this image