Don't wanna be here? Send us removal request.
Text
Week 2 assignment
This assignment involved looking at the use and dependency of opioids. I selected the NESARC dataset.
Let me Describe:
I began by importing the Libraries pandas and numpy. Then the NESARC dataset. I printed the rows and columns in the data, and summarized the age of the individuals in the data. I created a smaller dataset of just those that had taken opioids. Since I initially assumed that these were people prescribed opioids (the field is listed under Medicine Use). The fields described in NESARC-III (NIAAA) suggest that the field may pertain to opioids taken without a prescription.
The Results
The NESARC dataset includes interviews from 43,093 participants and 3,010 variables of data. Sample participants had a mean age of 46.4 ± 18.2 (mean ± sd, median 44). 1,301 (roughly 3%) of the sample participants had taken opioids at some point, though 320 individuals were non-respondents. The mean age and standard deviation of individuals that had taken opioids was 39.4 ± 13.3. The West and Pacific Census regions and divisions appear to have greater proportions of individuals who had taken opioids than censused. While only about 1.8% (n=24) of the individuals who said they tried opioids said they had an opioid dependency issue in the last 12 months, about 5.7% (n = 75) of the individuals that had tried opioids responded that they experienced an opioid dependency prior to the last 12 months.
Written code
# -*- coding: utf-8 -*-
Spyder Editor
#Import Libraries
import pandas
import numpy
#Read In Data
data = pandas.read_csv('_c10361280c0613304594ab464c014f47_nesarc_pds.csv',low_memory=False)
#Print the Number of Rows in the Dataset
print(len(data))
#Print the Number of Columns in the Dataset
print(len(data.columns))
#Print the Three Number Summary and 2 Moments That Pertain to Age of Interviewees
print(numpy.min(data["AGE"]))
print(numpy.median(data["AGE"]))
print(numpy.max(data["AGE"]))
print(numpy.mean(data["AGE"]))
print(numpy.std(data["AGE"]))
print('Count and Percent of Surveyed Individuals that Used Opioids')
print('(1=Yes 2=No 3=Unknown)')
data["S3BQ1A2"].value_counts(sort=False, normalize=True)
print(data["S3BQ1A2"].value_counts(sort=False))
print(data["S3BQ1A2"].value_counts(sort=False, normalize=True))
#Subset the Data for Individuals Who have Used Opioids
sub1=data[data['S3BQ1A2']==1]
print('Number of Individuals That Used Opioids')
print(len(sub1))
print(numpy.min(sub1["AGE"]))
print(numpy.median(sub1["AGE"]))
print(numpy.max(sub1["AGE"]))
print(numpy.mean(sub1["AGE"]))
print(numpy.std(sub1["AGE"]))
#Calculate and Print Counts from the Variables in the Dataset
print('Count and Percent of Individuals in US Regions')
print('(1=Northeast 2=Midwest 3=South 4=West)')
print(data["REGION"].value_counts(sort=False))
print(data["REGION"].value_counts(sort=False, normalize=True))
print('Count and Percent of Individuals That Used Opioids by Region')
print(sub1["REGION"].value_counts(sort=False))
print(sub1["REGION"].value_counts(sort=False, normalize=True))
print('Count and Percent of Individuals in Census Divisions')
print('(1=New England 2=Mid Atlantic 3=E. N. Central 4=W. N. Central 5=S. Atlantic 6=E. S. Central 7 = W. S. Central 8=Mountain 9=Pacific)')
print(data["CENDIV"].value_counts(sort=False))
print(data["CENDIV"].value_counts(sort=False, normalize=True))
print('Count and Percent of Individuals That Used Opioids by Divisions')
print(sub1["CENDIV"].value_counts(sort=False))
print(sub1["CENDIV"].value_counts(sort=False, normalize=True))
print('Count and Percent of Individuals in City (1) or Rural(2) MSA')
print(data["CCS"].value_counts(sort=False))
print(data["CCS"].value_counts(sort=False, normalize=True))
print('Count and Percent of Individuals That Used Individuals by Environs')
print(sub1["CCS"].value_counts(sort=False))
print(sub1["CCS"].value_counts(sort=False, normalize=True))
###### Opioid Users Only
print('Count and Percent of Individuals That Used Opioid with History of Abuse/Dependency in the Last 12 Mos')
print('(0 = None 1=Abuse 2=Dependence 3=Abuse and Dependence)')
print(sub1["PAN12ABDEP"].value_counts(sort=False))
print(sub1["PAN12ABDEP"].value_counts(sort=False, normalize=True))
print('Count and Percent of Individuals That Used Opioid with History of Abuse/Dependency Prior to Last 12 Mos')
print('(0 = None 1=Abuse 2=Dependence 3=Abuse and Dependence)')
print(sub1["PANP12ABDEP"].value_counts(sort=False))
print(sub1["PANP12ABDEP"].value_counts(sort=False, normalize=True))
The Output
Python 3.7.3 (default, Mar 27 2019, 17:13:21) [MSC v.1915 64 bit (AMD64)]
Type "copyright", "credits" or "license" for more information.
IPython 7.4.0 -- An enhanced Interactive Python.
In [1]: runfile('C:/Users/XXXXXXXXXXXXXXXXXXXXXXX/Documents/Coursera/Wes1 Data Mgmt and Visualization/Week 2/Week2.py', wdir='C:/Users/The Eurypterid/Documents/Coursera/Wes1 Data Mgmt and Visualization/Week 2')
43093
3010
18
44.0
98
46.40080755575151
18.17840080853223
Count and Percent of Surveyed Individuals that Used Opioids
(1=Yes 2=No 3=Unknown)
1 1301
2 41472
9 320
Name: S3BQ1A2, dtype: int64
1 0.030191
2 0.962384
9 0.007426
Name: S3BQ1A2, dtype: float64
Number of Individuals That Used Opioids
1301
18
40.0
93
39.36664104534973
13.310635978310472
Count and Percent of Individuals in US Regions
(1=Northeast 2=Midwest 3=South 4=West)
1 8209
2 8991
3 16156
4 9737
Name: REGION, dtype: int64
1 0.190495
2 0.208642
3 0.374910
4 0.225953
Name: REGION, dtype: float64
Count and Percent of Individuals That Used Opioids by Region
1 201
2 269
3 461
4 370
Name: REGION, dtype: int64
1 0.154497
2 0.206764
3 0.354343
4 0.284397
Name: REGION, dtype: float64
Count and Percent of Individuals in Census Divisions
(1=New England 2=Mid Atlantic 3=E. N. Central 4=W. N. Central 5=S. Atlantic 6=E. S. Central 7 = W. S. Central 8=Mountain 9=Pacific)
1 2018
2 6191
3 6430
4 2561
5 8665
6 2658
7 4832
8 3046
9 6692
Name: CENDIV, dtype: int64
1 0.046829
2 0.143666
3 0.149212
4 0.059430
5 0.201077
6 0.061681
7 0.112130
8 0.070684
9 0.155292
Name: CENDIV, dtype: float64
Count and Percent of Individuals That Used Opioids by Divisions
1 48
2 153
3 180
4 89
5 248
6 81
7 132
8 117
9 253
Name: CENDIV, dtype: int64
1 0.036895
2 0.117602
3 0.138355
4 0.068409
5 0.190623
6 0.062260
7 0.101460
8 0.089931
9 0.194466
Name: CENDIV, dtype: float64
Count and Percent of Individuals in City (1) or Rural(2) MSA
1 15002
2 20295
3 7796
Name: CCS, dtype: int64
1 0.348131
2 0.470958
3 0.180911
Name: CCS, dtype: float64
Count and Percent of Individuals That Used Individuals by Environs
1 505
2 588
3 208
Name: CCS, dtype: int64
1 0.388163
2 0.451960
3 0.159877
Name: CCS, dtype: float64
Count and Percent of Individuals That Used Opioid with History of Abuse/Dependency in the Last 12 Mos
(0 = None 1=Abuse 2=Dependence 3=Abuse and Dependence)
0 1239
1 38
2 8
3 16
Name: PAN12ABDEP, dtype: int64
0 0.952344
1 0.029208
2 0.006149
3 0.012298
Name: PAN12ABDEP, dtype: float64
The Count and Percent of Individuals That Used Opioid with History of Abuse/Dependency Prior to Last 12 Mos
(0 = None 1=Abuse 2=Dependence 3=Abuse and Dependence)
0 1013
1 213
2 9
3 66
Name: PANP12ABDEP, dtype: int64
0 0.778632
1 0.163720
2 0.006918
3 0.050730
Name: PANP12ABDEP, dtype: float64
References used
National Institutes of Health, National Institutes of Alcohol Abuse and Alcoholism. (n.d.) National Epidemiologic Survey on Alcohol and Related Conditions. https://www.niaaa.nih.gov/research/nesarc-iii
0 notes