In [1]:
import numpy as np
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
%matplotlib inline
In [2]:
file = pd.read_csv('nsduh-2015.csv')
df = pd.DataFrame(file)
In [3]:
df.shape
Out[3]:
In [4]:
df.drop(df.columns[[0,1]], axis=1, inplace=True)
In [5]:
df.columns
Out[5]:
In [6]:
df.shape
Out[6]:
In [7]:
df['HEROINEVR'].value_counts()
Out[7]:
In [8]:
df['AGECAT'].value_counts()
Out[8]:
In [9]:
df.describe()
Out[9]:
In [10]:
df.keys()
Out[10]:
In [11]:
columns = ['PRLMISEVR','HYDRCDYR']
for col in columns:
print(df[[col]])
In [12]:
prl_evr = pd.crosstab(df['PRLMISEVR'], df['AGECAT'])
prl_evr
Out[12]:
In [13]:
prl_evr = pd.crosstab(df['HYDRCDYR'], df['AGECAT'])
prl_evr
Out[13]:
In [14]:
oxy_evr = pd.crosstab(df['OXYCDPRYR'], df['AGECAT'])
oxy_evr
Out[14]:
In [15]:
prl_evr = pd.crosstab(df['TRMADLYR'], df['AGECAT'])
prl_evr
Out[15]:
In [16]:
prl_evr = pd.crosstab(df['MORPHPRYR'], df['AGECAT'])
prl_evr
Out[16]:
In [17]:
prl_evr = pd.crosstab(df['FENTNYLYR'], df['AGECAT'])
prl_evr
Out[17]:
In [18]:
prl_evr = pd.crosstab(df['BUPRNRPHN'], df['AGECAT'])
prl_evr
Out[18]:
In [19]:
prl_evr = pd.crosstab(df['DEMEROL'], df['AGECAT'])
prl_evr
Out[19]:
In [20]:
prl_evr = pd.crosstab(df['OXYMORPHN'], df['AGECAT'])
prl_evr
Out[20]:
In [21]:
prl_evr = pd.crosstab(df['HYDRMRPHN'], df['AGECAT'])
prl_evr
Out[21]:
In [22]:
prl_evr = pd.crosstab(df['METHADONE'], df['AGECAT'])
prl_evr
Out[22]:
In [23]:
prl_evr = pd.crosstab(df['HEROINEVR'], df['AGECAT'])
prl_evr
Out[23]:
In [24]:
prl_evr = pd.crosstab(df['COCNEVR'], df['AGECAT'])
prl_evr
Out[24]:
In [25]:
prl_evr = pd.crosstab(df['METHEVR'], df['AGECAT'])
prl_evr
Out[25]:
In [26]:
prl_evr = pd.crosstab(df['TRQBENZODZ'], df['AGECAT'])
prl_evr
Out[26]:
In [27]:
prl_evr = pd.crosstab(df['SDOTHYR'], df['AGECAT'])
prl_evr
Out[27]:
In [28]:
prl_evr = pd.crosstab(df['AMPHTMNYR'], df['AGECAT'])
prl_evr
Out[28]:
In [29]:
hlc_evr = pd.crosstab(df['HLCNEVR'], df['AGECAT'])
hlc_evr
Out[29]:
In [30]:
hlc_evr = pd.crosstab(df['LSDEVR'], df['AGECAT'])
hlc_evr
Out[30]:
In [31]:
hlc_evr = pd.crosstab(df['MDMAEVR'], df['AGECAT'])
hlc_evr
Out[31]:
In [32]:
mde_evr = pd.crosstab(df['HOSPYR'], df['AGECAT'])
mde_evr
Out[32]:
In [33]:
mde_evr = pd.crosstab(df['DEPMELT'], df['AGECAT'])
mde_evr
Out[33]:
In [34]:
mde_evr = pd.crosstab(df['SUICTHT'], df['AGECAT'])
mde_evr
Out[34]:
In [35]:
trtm_evr = pd.crosstab(df['MHTRTOYR'], df['AGECAT'])
trtm_evr
Out[35]:
In [36]:
trtm_evr = pd.crosstab(df['MHTRTTHPY'], df['AGECAT'])
trtm_evr
Out[36]:
In [37]:
trtm_evr = pd.crosstab(df['TRTGAPYR'], df['AGECAT'])
trtm_evr
Out[37]:
In [38]:
her_evr = pd.crosstab(df['HEROINEVR'], df['AGECAT'])
her_evr
Out[38]:
In [39]:
df.drop('SUICATT', 1, inplace=True)
df.keys()
Out[39]:
In [40]:
heroin_sex = pd.crosstab(df['HEROINEVR'], df['SEX'])
heroin_sex
Out[40]:
In [41]:
opioid_evr = pd.crosstab(df['HEROINEVR'], df['PRLMISEVR'])
opioid_evr
Out[41]:
In [42]:
opioid_pct = opioid_evr.div(opioid_evr.sum(1), axis=0)
opioid_pct
Out[42]:
In [43]:
opioid_pct.plot.bar()
plt.savefig('opioids.png', bbox_inches='tight')
In [47]:
prl_any = pd.crosstab(df['AGECAT'],df['PRLMISEVR'])
prl_any
Out[47]:
In [48]:
prl_any_pct = prl_any.div(prl_any.sum(1), axis=0)
prl_any_pct
Out[48]:
In [49]:
prl_any_pct.plot.bar()
Out[49]:
In [50]:
df.keys()
Out[50]: