0. Setup

Import modules


In [1]:
import numpy as np
import pandas as pd
import re
import datetime

In [2]:
%pylab inline


Populating the interactive namespace from numpy and matplotlib

Import source data


In [3]:
allyears = pd.read_csv('https://dl.dropboxusercontent.com/u/39570370/allyears.csv')
searchcodes = pd.read_csv('https://raw.githubusercontent.com/rinina/PCC-Opioid-Project/master/data/searchcodes.csv', dtype=str)

Clean up and format source data


In [4]:
allyears = allyears.dropna(subset=['Substance'])
allyears = allyears[allyears['Medical Outcome'] != 'Confirmed nonexposure']
allyears['Start Date'] = pd.to_datetime(allyears['Start Date'])

Find opioid matches


In [5]:
matched = allyears[allyears['Substance'].str.contains('|'.join(searchcodes['Code number'].values))]

1. Opioid Types

Get counts for each opioid


In [6]:
opioid_counts = (searchcodes.set_index('Opioid name')['Code number']
                .apply(lambda x: len(matched[matched['Substance'].str.contains(x)]))
                .order(ascending=False).reset_index()
                .rename(columns={'Code number' : 'Count'}))

opioid_counts


Out[6]:
Opioid name Count
0 Acetaminophen with Oxycodone 1777
1 Acetaminophen with Hydrocodone 1746
2 Oxycodone Alone or in Combination (Excluding C... 1420
3 Tramadol 1114
4 Morphine 725
5 Methadone 444
6 Other or Unknown Narcotics 413
7 Acetaminophen with Codeine 357
8 Buprenorphine 234
9 Codeine 180
10 Fentanyl 96
11 Hydromorphone 78
12 Oxymorphone 26
13 Tapentadol 20
14 Propoxyphene 16
15 Meperidine 16
16 Acetylsalicylic Acid with Oxycodone 9
17 Acetylsalicylic Acid with Codeine 4
18 Butorphanol 4
19 Pentazocine 1
20 Levorphanol 1

Deaths


In [7]:
opioid_deaths = (searchcodes.set_index('Opioid name')['Code number']
             .apply(lambda x: len(matched[matched['Medical Outcome']
             .str.contains('Death') & (matched['Substance'].str.contains(x))]))
             .replace(0, np.nan).dropna().reset_index().rename(columns={'Code number':'Deaths'}))

opioid_deaths.sort('Deaths', ascending=False)


Out[7]:
Opioid name Deaths
6 Oxycodone Alone or in Combination (Excluding C... 17
5 Other or Unknown Narcotics 9
8 Acetaminophen with Hydrocodone 9
4 Morphine 8
9 Acetaminophen with Oxycodone 8
3 Methadone 6
1 Codeine 3
7 Tramadol 2
0 Buprenorphine 1
2 Fentanyl 1

All outcomes by opioid


In [8]:
opioid_outcomes = {}

for i in matched['Medical Outcome'].dropna().unique():
    outcome = (searchcodes.set_index('Opioid name')['Code number']
               .apply(lambda x:len(matched[(matched['Medical Outcome'] == i) & (matched['Substance'].str.contains(x))]))
               .replace(0, np.nan).dropna().reset_index().rename(columns={'Code number':i}))
    opioid_outcomes.update({i : outcome.set_index('Opioid name')})
    
opioid_outcomes = pd.concat(opioid_outcomes.values(), axis=1)
opioid_outcomes


Out[8]:
Unrelated effect, the exposure was probably not responsible for the effect(s) Major effect Unable to follow, judged as a potentially toxic exposure Death Moderate effect Not followed, minimal clinical effects possible (no more than minor effect possible) Death, indirect report No effect Minor effect Not followed, judged as nontoxic exposure (clinical effects not expected)
Acetaminophen with Codeine 9 2 43 NaN 32 61 NaN 75 123 12
Acetaminophen with Hydrocodone 48 38 221 9 236 314 NaN 282 567 30
Acetaminophen with Oxycodone 51 47 214 6 290 253 2 278 599 36
Acetylsalicylic Acid with Codeine NaN NaN 1 NaN NaN NaN NaN 1 2 NaN
Acetylsalicylic Acid with Oxycodone NaN NaN NaN NaN 1 3 NaN 3 2 NaN
Buprenorphine 4 4 43 1 30 51 NaN 16 83 2
Butorphanol NaN NaN NaN NaN NaN 1 NaN 3 NaN NaN
Codeine 6 5 9 3 19 43 NaN 49 41 5
Fentanyl 1 7 15 1 30 7 NaN 3 31 1
Hydromorphone 2 3 12 NaN 12 20 NaN 8 21 NaN
Levorphanol NaN NaN NaN NaN NaN NaN NaN NaN 1 NaN
Meperidine 1 NaN NaN NaN 3 4 NaN 5 3 NaN
Methadone 10 32 60 6 140 46 NaN 29 118 3
Morphine 11 30 101 8 156 127 NaN 96 191 4
Other or Unknown Narcotics 13 38 35 9 145 32 NaN 24 114 3
Oxycodone Alone or in Combination (Excluding Combination Products with Acetaminophen or Acetylsalicylic Acid) 29 44 198 17 290 212 NaN 173 445 10
Oxymorphone NaN 3 4 NaN 7 2 NaN 4 6 NaN
Pentazocine NaN NaN 1 NaN NaN NaN NaN NaN NaN NaN
Propoxyphene NaN 2 2 NaN 3 2 NaN 2 4 1
Tapentadol 1 1 1 NaN 4 1 NaN 7 5 NaN
Tramadol 26 22 118 2 214 172 NaN 193 359 7

In [9]:
opioid_outcomes.plot(kind='bar', stacked=True, figsize=(20,20))
title('Outcomes by Opioid')
ylabel('Count')


Out[9]:
<matplotlib.text.Text at 0x7f996651d250>

All reasons by opioid


In [10]:
opioid_reasons = {}

for i in matched['Reason'].dropna().unique():
    outcome = (searchcodes.set_index('Opioid name')['Code number']
               .apply(lambda x:len(matched[(matched['Reason'] == i) & (matched['Substance'].str.contains(x))]))
               .replace(0, np.nan).dropna().reset_index().rename(columns={'Code number':i}))
    opioid_reasons.update({i : outcome.set_index('Opioid name')})
    
opioid_reasons = pd.concat(opioid_reasons.values(), axis=1)
opioid_reasons


Out[10]:
Intentional - Misuse Unknown reason Unintentional - General Adverse reaction - Drug Intentional - Suspected suicide Unintentional - Therapeutic error Intentional - Abuse Unintentional - Unknown Unintentional - Misuse Adverse reaction - Other Intentional - Unknown Other - Withdrawal Other - Malicious Unintentional - Bite / sting Unintentional - Occupational Other - Contamination / tampering Adverse reaction - Food
Acetaminophen with Codeine 33 2 69 38 116 72 11 NaN 5 NaN 9 1 1 NaN NaN NaN NaN
Acetaminophen with Hydrocodone 194 10 256 121 689 252 101 3 51 2 54 12 NaN NaN NaN 1 NaN
Acetaminophen with Oxycodone 192 11 286 137 645 180 163 7 40 2 90 22 1 1 NaN NaN NaN
Acetylsalicylic Acid with Codeine NaN NaN NaN NaN 1 NaN 2 NaN NaN NaN 1 NaN NaN NaN NaN NaN NaN
Acetylsalicylic Acid with Oxycodone 1 NaN 1 NaN 2 3 1 NaN 1 NaN NaN NaN NaN NaN NaN NaN NaN
Buprenorphine 24 1 75 30 21 18 36 NaN 3 1 8 16 NaN NaN NaN NaN 1
Butorphanol NaN NaN 1 1 NaN 2 NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
Codeine 5 NaN 43 17 33 63 13 NaN 3 1 2 NaN NaN NaN NaN NaN NaN
Fentanyl 7 1 15 17 19 6 21 1 3 NaN 6 NaN NaN NaN NaN NaN NaN
Hydromorphone 9 NaN 8 7 23 17 7 NaN NaN NaN 5 2 NaN NaN NaN NaN NaN
Levorphanol NaN NaN NaN NaN 1 NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
Meperidine 3 NaN 3 1 3 5 NaN NaN NaN NaN NaN 1 NaN NaN NaN NaN NaN
Methadone 31 13 61 37 122 40 82 3 NaN 1 24 28 NaN 1 NaN 1 NaN
Morphine 72 9 107 57 176 146 88 2 15 1 30 20 NaN 1 NaN 1 NaN
Other or Unknown Narcotics 23 7 55 28 131 18 67 2 5 NaN 36 39 1 NaN 1 NaN NaN
Oxycodone Alone or in Combination (Excluding Combination Products with Acetaminophen or Acetylsalicylic Acid) 119 13 238 91 423 226 168 4 29 2 71 35 NaN 1 NaN NaN NaN
Oxymorphone 3 NaN 4 1 6 5 3 NaN 1 NaN 1 2 NaN NaN NaN NaN NaN
Pentazocine NaN NaN 1 NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
Propoxyphene 1 3 1 NaN 7 2 1 NaN NaN NaN 1 NaN NaN NaN NaN NaN NaN
Tapentadol 1 NaN 2 3 6 6 1 NaN NaN NaN NaN 1 NaN NaN NaN NaN NaN
Tramadol 117 8 214 119 387 135 59 3 18 NaN 41 12 1 NaN NaN NaN NaN

In [11]:
opioid_reasons.plot(kind='bar', stacked=True, figsize=(20,20))
title('Reasons for call by Opioid')
ylabel('Count')


Out[11]:
<matplotlib.text.Text at 0x7f996651de90>

2. Reasons


In [12]:
matched_reasons = matched.groupby('Reason').size().order(ascending=False).reset_index().rename(columns={0:'Matched Count'})

matched_reasons


Out[12]:
Reason Matched Count
0 Intentional - Suspected suicide 2579
1 Unintentional - General 1388
2 Unintentional - Therapeutic error 1158
3 Intentional - Misuse 777
4 Intentional - Abuse 754
5 Adverse reaction - Drug 666
6 Intentional - Unknown 343
7 Other - Withdrawal 176
8 Unintentional - Misuse 157
9 Unknown reason 70
10 Unintentional - Unknown 22
11 Adverse reaction - Other 9
12 Unintentional - Bite / sting 4
13 Other - Malicious 4
14 Other - Contamination / tampering 3
15 Unintentional - Occupational 1
16 Adverse reaction - Food 1

3. Outcomes


In [13]:
matched_outcomes = matched.groupby('Medical Outcome').size().order(ascending=False).reset_index().rename(columns={0:'Count'})

matched_outcomes


Out[13]:
Medical Outcome Count
0 Minor effect 2537
1 Moderate effect 1446
2 Not followed, minimal clinical effects possibl... 1289
3 No effect 1210
4 Unable to follow, judged as a potentially toxi... 999
5 Major effect 250
6 Unrelated effect, the exposure was probably no... 206
7 Not followed, judged as nontoxic exposure (cli... 113
8 Death 54
9 Death, indirect report 2

4. Gender


In [14]:
matched['Gender'].replace('Pregnant', 'Female', inplace=True)


/usr/local/lib/python2.7/dist-packages/pandas/core/generic.py:2674: SettingWithCopyWarning: 
A value is trying to be set on a copy of a slice from a DataFrame

See the the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/indexing.html#indexing-view-versus-copy
  self._update_inplace(new_data)

In [15]:
gender_totals = matched.groupby('Gender').size().reset_index().rename(columns={0:'Count'})

gender_totals


Out[15]:
Gender Count
0 Female 4690
1 Male 3369
2 Unknown 53

In [16]:
reasons_by_gender = (matched.groupby(['Gender', 'Reason']).size()
                    .unstack().T)

reasons_by_gender


Out[16]:
Gender Female Male Unknown
Reason
Adverse reaction - Drug 418 247 1
Adverse reaction - Food NaN 1 NaN
Adverse reaction - Other 5 4 NaN
Intentional - Abuse 295 451 8
Intentional - Misuse 436 339 2
Intentional - Suspected suicide 1657 908 14
Intentional - Unknown 189 150 4
Other - Contamination / tampering 2 1 NaN
Other - Malicious 3 1 NaN
Other - Withdrawal 96 79 1
Unintentional - Bite / sting 1 3 NaN
Unintentional - General 708 664 16
Unintentional - Misuse 94 61 2
Unintentional - Occupational NaN 1 NaN
Unintentional - Therapeutic error 729 426 3
Unintentional - Unknown 14 8 NaN
Unknown reason 43 25 2

In [17]:
reasons_by_gender.plot(kind='bar', figsize=(10,7))
xlabel('')


Out[17]:
<matplotlib.text.Text at 0x7f9965251110>

Abuse and misuse by gender


In [18]:
matched[(matched['Reason'] == 'Intentional - Abuse') | (matched['Reason'] == 'Intentional - Misuse')].groupby('Gender').size()


Out[18]:
Gender
Female     731
Male       790
Unknown     10
dtype: int64

Unintentional and adverse by gender


In [19]:
matched[matched['Reason'].str.contains('Unintentional|Adverse')].groupby('Gender').size()


Out[19]:
Gender
Female     1969
Male       1415
Unknown      22
dtype: int64

5. Age groups


In [20]:
matched_age = matched[matched['Age Unit'] == 'Years']

def age_group(age):
    if 1 <= age <= 4:
        return '1-4'
    elif 5 <= age <= 14:
        return '5-14'
    elif 15 <= age <= 24:
        return '15-24'
    elif 25 <= age <= 34:
        return '25-34'
    elif 35 <= age <= 44:
        return '35-44'
    elif 45 <= age <= 54:
        return '45-54'
    elif 55 <= age <= 64:
        return '55-64'
    elif 65 <= age <= 74:
        return '65-74'
    elif 75 <= age <= 84:
        return '75-84'
    elif age > 84:
        return '85+'
    else:
        return 'Unknown'
    
matched_age['Age_group'] = matched_age['Age'].apply(age_group)


-c:27: SettingWithCopyWarning: 
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead

See the the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/indexing.html#indexing-view-versus-copy

Opioid calls by age


In [21]:
age_counts = matched_age.groupby('Age_group').size().reset_index().rename(columns={0 : 'Count'})

age_counts


Out[21]:
Age_group Count
0 1-4 509
1 15-24 1308
2 25-34 1504
3 35-44 1147
4 45-54 1101
5 5-14 275
6 55-64 758
7 65-74 315
8 75-84 184
9 85+ 54

Suicides by age


In [22]:
suicides_by_age = (matched_age[matched_age['Reason'] == 'Intentional - Suspected suicide']
                   .groupby('Age_group').size().reset_index().rename(columns={0 : 'Suicides'}))

suicides_by_age


Out[22]:
Age_group Suicides
0 15-24 506
1 25-34 567
2 35-44 494
3 45-54 481
4 5-14 50
5 55-64 250
6 65-74 73
7 75-84 35
8 85+ 8

Intentional abuse by age


In [23]:
abuse_by_age = (matched_age[matched_age['Reason'] == 'Intentional - Abuse']
                .groupby('Age_group').size().reset_index().rename(columns={0 : 'Intent. Abuse'}))

abuse_by_age


Out[23]:
Age_group Intent. Abuse
0 15-24 222
1 25-34 173
2 35-44 80
3 45-54 84
4 5-14 27
5 55-64 53
6 65-74 18

In [24]:
intent_by_age = (matched_age[(matched_age['Reason'] == 'Intentional - Abuse') | (matched['Reason']== 'Intentional - Misuse')]
.groupby('Age_group').size().reset_index().rename(columns={0 : 'Intent. Abuse or Misuse'}))

intent_by_age


Out[24]:
Age_group Intent. Abuse or Misuse
0 15-24 377
1 25-34 347
2 35-44 202
3 45-54 198
4 5-14 39
5 55-64 137
6 65-74 43
7 75-84 14
8 85+ 2

In [25]:
unintent_by_age = (matched_age[matched_age['Reason'].str.contains('Unintentional|Adverse')]
                 .groupby('Age_group').size().reset_index().rename(columns={0 : 'Unintent or Adverse'}))

unintent_by_age


Out[25]:
Age_group Unintent or Adverse
0 1-4 509
1 15-24 348
2 25-34 449
3 35-44 362
4 45-54 333
5 5-14 173
6 55-64 299
7 65-74 175
8 75-84 132
9 85+ 42

Combined reasons


In [26]:
age_reasons = pd.concat([i.set_index('Age_group') for i in [suicides_by_age, intent_by_age, unintent_by_age]], axis=1)

age_reasons.replace(np.nan, 0)


Out[26]:
Suicides Intent. Abuse or Misuse Unintent or Adverse
1-4 0 0 509
15-24 506 377 348
25-34 567 347 449
35-44 494 202 362
45-54 481 198 333
5-14 50 39 173
55-64 250 137 299
65-74 73 43 175
75-84 35 14 132
85+ 8 2 42

In [27]:
age_reasons.iloc[[0,5,1,2,3,4,6,7,8,9]].plot(kind='bar', stacked=True, figsize=(15,10))

title('Brief reasons by age')
xlabel('Age group')


Out[27]:
<matplotlib.text.Text at 0x7f99641f8690>

Full reasons by age


In [28]:
age_full_reasons = matched_age.groupby(['Age_group', 'Reason']).size().unstack().T

age_full_reasons.replace(np.nan, '').iloc[:, [0,5,1,2,3,4,6,7,8,9]] #The iloc is used to reorder so that 5-14 comes after 1-4


Out[28]:
Age_group 1-4 5-14 15-24 25-34 35-44 45-54 55-64 65-74 75-84 85+
Reason
Adverse reaction - Drug 3 10 116 146 75 77 62 36 25 4
Adverse reaction - Food 1
Adverse reaction - Other 2 2 3 1
Intentional - Abuse 27 222 173 80 84 53 18
Intentional - Misuse 12 155 174 122 114 84 25 14 2
Intentional - Suspected suicide 50 506 567 494 481 250 73 35 8
Intentional - Unknown 8 50 78 56 50 37 14 3 2
Other - Contamination / tampering 1 1
Other - Malicious 1 2
Other - Withdrawal 2 18 42 25 23 27 6
Unintentional - Bite / sting 1 1 1 1
Unintentional - General 470 76 102 110 89 76 64 35 21 6
Unintentional - Misuse 4 21 34 23 29 16 9 2 2
Unintentional - Therapeutic error 35 80 99 158 167 145 153 95 84 29
Unintentional - Unknown 6 1 4 5 4 1
Unknown reason 3 7 19 8 15 8 4

In [29]:
age_full_reasons.iloc[:, [0,5,1,2,3,4,6,7,8,9]].T.plot(kind='bar', stacked=True, figsize=(15,10))

title('All reasons by age')
xlabel('Age group')


Out[29]:
<matplotlib.text.Text at 0x7f9964286bd0>

Percent of cases for each age group by reason


In [30]:
(100*matched_age.groupby(['Age_group', 'Reason']).size().unstack().astype(float)
 .div(matched_age.groupby('Age_group').size().values, axis=0).T)


Out[30]:
Age_group 1-4 15-24 25-34 35-44 45-54 5-14 55-64 65-74 75-84 85+
Reason
Adverse reaction - Drug 0.589391 8.868502 9.707447 6.538797 6.993642 3.636364 8.179420 11.428571 13.586957 7.407407
Adverse reaction - Food NaN 0.076453 NaN NaN NaN NaN NaN NaN NaN NaN
Adverse reaction - Other NaN 0.152905 NaN 0.261552 0.090827 0.727273 NaN NaN NaN NaN
Intentional - Abuse NaN 16.972477 11.502660 6.974717 7.629428 9.818182 6.992084 5.714286 NaN NaN
Intentional - Misuse NaN 11.850153 11.569149 10.636443 10.354223 4.363636 11.081794 7.936508 7.608696 3.703704
Intentional - Suspected suicide NaN 38.685015 37.699468 43.068875 43.687557 18.181818 32.981530 23.174603 19.021739 14.814815
Intentional - Unknown NaN 3.822630 5.186170 4.882302 4.541326 2.909091 4.881266 4.444444 1.630435 3.703704
Other - Contamination / tampering NaN 0.076453 NaN NaN 0.090827 NaN NaN NaN NaN NaN
Other - Malicious NaN 0.076453 0.132979 NaN NaN NaN NaN NaN NaN NaN
Other - Withdrawal NaN 1.376147 2.792553 2.179599 2.089010 0.727273 3.562005 1.904762 NaN NaN
Unintentional - Bite / sting 0.196464 0.076453 NaN 0.087184 NaN 0.363636 NaN NaN NaN NaN
Unintentional - General 92.337917 7.798165 7.313830 7.759372 6.902816 27.636364 8.443272 11.111111 11.413043 11.111111
Unintentional - Misuse NaN 1.605505 2.260638 2.005231 2.633969 1.454545 2.110818 2.857143 1.086957 3.703704
Unintentional - Therapeutic error 6.876228 7.568807 10.505319 14.559721 13.169846 29.090909 20.184697 30.158730 45.652174 53.703704
Unintentional - Unknown NaN 0.458716 0.066489 0.348736 0.454133 NaN 0.527704 NaN NaN 1.851852
Unknown reason NaN 0.535168 1.263298 0.697472 1.362398 1.090909 1.055409 1.269841 NaN NaN

6. Comparison to heroin


In [31]:
heroin = allyears[allyears['Substance'].str.contains('Heroin', re.IGNORECASE)]

print len(heroin)
print len(matched)


542
8112

7. Time Series


In [32]:
matched_ts = matched.groupby([matched['Start Date'].dt.year, matched['Start Date'].dt.month]).size()
matched_ts.index = matched_ts.reset_index().apply(lambda x: datetime.datetime(x['level_0'], x['level_1'], 1), axis=1)

matched_ts.plot()
title('Time series of calls by month (2010-2014)')
xlabel('Time')
ylabel('Calls')


Out[32]:
<matplotlib.text.Text at 0x7f9963fa8950>

In [33]:
by_mo = matched.groupby(matched['Start Date'].dt.month).size()
by_mo.plot()

title('Total calls by month')
xlim(1,12)
xlabel('Month')
ylabel('Calls')


Out[33]:
<matplotlib.text.Text at 0x7f9962423bd0>

Suicides by month


In [34]:
matched_suicides = matched[matched['Reason']=='Intentional - Suspected suicide']
allyears_suicides = allyears[allyears['Reason']=='Intentional - Suspected suicide']

pd.concat([matched_suicides.groupby(matched_suicides['Start Date'].dt.month).size(),
           allyears_suicides.groupby(allyears_suicides['Start Date'].dt.month).size()],
          axis=1).rename(columns={0:'Opioid', 1:'All Calls'})


Out[34]:
Opioid All Calls
1 188 1554
2 179 1480
3 230 1701
4 227 1643
5 251 1621
6 216 1573
7 248 1624
8 227 1704
9 231 1696
10 229 1592
11 194 1511
12 159 1381

8. Therapy


In [35]:
matched_therapy = matched.dropna(subset=['Therapy'])

In [36]:
matched_therapy[matched_therapy['Therapy'].str.contains('Naloxone')].groupby('Reason').size()


Out[36]:
Reason
Adverse reaction - Drug               39
Intentional - Abuse                  182
Intentional - Misuse                  84
Intentional - Suspected suicide      622
Intentional - Unknown                 80
Other - Malicious                      1
Other - Withdrawal                     3
Unintentional - Bite / sting           3
Unintentional - General               98
Unintentional - Misuse                13
Unintentional - Therapeutic error     20
Unintentional - Unknown                5
Unknown reason                        22
dtype: int64

In [37]:
matched_death = matched[matched['Medical Outcome']=='Death']

In [38]:
matched_death.groupby('Reason').size()


Out[38]:
Reason
Adverse reaction - Drug             1
Intentional - Abuse                 7
Intentional - Misuse                2
Intentional - Suspected suicide    30
Intentional - Unknown               5
Unintentional - Bite / sting        1
Unintentional - General             3
Unknown reason                      5
dtype: int64

In [39]:
matched['Therapy'].dropna().unique()


Out[39]:
array(['Dilute/irrigate/wash(RP)',
       'Calcium(RP), Fluids, IV(RP), Other(RP)',
       'Cardioversion(P), CPR(P), Fluids, IV(P), Intubation(P), NAC, IV(RP), Oxygen(P), Ventilator(P)',
       ...,
       'Alkalinization(RP), Antihistamines(P), Fluids, IV(RP), Other(RP), Benzodiazepines(RP)',
       'Fluids, IV(RP), Antibiotics(P), Benzodiazepines(P)',
       'Intubation(P), NAC, IV(RP), Naloxone(P), Oxygen(P), Ventilator(P), Sedation (other)(P)'], dtype=object)

In [40]:
matched['Clinical Effect'].unique()


Out[40]:
array(['Hallucinations/delusions (UR)', nan,
       'Tachycardia (R), Drowsiness/lethargy (R)', ...,
       'Tachycardia (UR), Hallucinations/delusions (UR), Fever/hyperthermia (UR), Other (UR)',
       'Tachycardia (UR), Coma (R), Respiratory depression (R), Acidosis (R)',
       'Tachycardia (R), ECG change (other) (R)'], dtype=object)

9. Exposure site


In [41]:
matched['Exposure Site'].unique()


Out[41]:
array(['Own residence', 'Public area', 'Health care facility', 'School',
       'Unknown', 'Other residence', 'Workplace', 'Other'], dtype=object)

In [42]:
matched.groupby('Exposure Site').size()


Out[42]:
Exposure Site
Health care facility      20
Other                      3
Other residence           36
Own residence           7970
Public area               41
School                    17
Unknown                   15
Workplace                 10
dtype: int64

10. Ethanol


In [43]:
matched[matched['Substance'].str.contains('[Ee]thanol')].groupby('Reason').size()


Out[43]:
Reason
Adverse reaction - Drug               13
Adverse reaction - Other               1
Intentional - Abuse                   71
Intentional - Misuse                  38
Intentional - Suspected suicide      336
Intentional - Unknown                 28
Other - Contamination / tampering      1
Other - Withdrawal                     8
Unintentional - General               39
Unintentional - Misuse                 5
Unintentional - Therapeutic error      5
Unknown reason                         4
dtype: int64

11. Secondary Substances


In [44]:
secondary_substances = (pd.Series(np.concatenate(matched['Substance'].str.split(' ; ').apply(np.array).values))
 .str.split('[').str[0].str.split(' - ').apply(pd.Series).apply(lambda x: x.str.strip())).groupby(0).size().order(ascending=False).drop(searchcodes['Opioid name'])

Secondary substances by outcome


In [45]:
secondary_compare = matched.groupby('Medical Outcome').size()
secondary_compare.name = 'All calls'

for i in pd.Series(secondary_substances.index).str.split('\(').str[0].str.strip().values:
    sub = matched[matched['Substance'].str.contains(i)].groupby('Medical Outcome').size()
    sub.name = i
    secondary_compare = pd.concat([secondary_compare, sub], axis=1)
    
secondary_compare.T.replace(np.nan, 0)


Out[45]:
Death Death, indirect report Major effect Minor effect Moderate effect No effect Not followed, judged as nontoxic exposure (clinical effects not expected) Not followed, minimal clinical effects possible (no more than minor effect possible) Unable to follow, judged as a potentially toxic exposure Unrelated effect, the exposure was probably not responsible for the effect(s)
All calls 54 2 250 2537 1446 1210 113 1289 999 206
Benzodiazepines 19 0 64 394 377 63 1 81 127 18
Ethanol 5 0 22 203 165 36 0 39 70 6
Carisoprodol 3 0 14 122 109 16 1 18 29 3
Atypical Antipsychotics 2 0 23 79 75 13 0 8 12 6
Acetaminophen Alone, Adult 2 1 23 61 52 23 14 12 11 3
Other Types of Sedative/Hypnotic/Anti-Anxiety or Anti-Psychotic Drug 1 0 9 73 69 9 0 19 15 3
Ibuprofen 1 0 7 77 40 33 2 26 13 2
Other Types of Selective Serotonin Reuptake Inhibitor 0 1 10 60 56 19 0 13 12 4
Other Types of Muscle Relaxant 2 0 14 49 68 14 0 10 14 3
Cyclobenzaprine 2 0 6 62 47 19 0 10 8 4
Other Antihistamines Alone 2 0 8 43 53 15 1 14 14 1
Other Types of Anticonvulsant 1 0 13 54 41 15 0 9 5 3
Trazodone 3 0 9 52 47 8 0 8 12 0
Beta Blockers 2 0 8 41 51 16 0 5 9 4
Other Types of Antidepressant 2 0 12 29 39 7 0 7 3 3
Ethanol 5 0 22 203 165 36 0 39 70 6
Systemic Antibiotic Preparations 2 0 2 33 12 12 1 20 8 3
Methamphetamines 4 0 6 29 35 6 0 6 13 0
Diphenhydramine Alone 4 0 4 46 26 9 0 12 10 3
Gabapentin 0 0 7 32 31 11 0 13 8 3
Amphetamines and Related Compounds 0 0 9 20 40 2 1 2 4 3
Amitriptyline 0 0 3 18 43 3 0 5 3 2
Angiotensin Converting Enzyme Inhibitors 0 0 4 21 20 14 0 2 5 2
Acetaminophen in Combination with Other Drugs, Adult Formulations 0 0 5 21 15 12 0 3 7 1
Heroin 3 0 1 20 21 3 1 3 7 1
Other Types of Miscellaneous Prescription or Over the Counter Drug 0 0 1 15 18 10 0 4 3 1
Other Types of Tricyclic Antidepressant 1 0 6 20 25 3 0 0 0 3
Marijuana 0 0 5 19 20 4 0 4 3 1
Cocaine 2 0 2 17 23 1 1 1 6 4
... ... ... ... ... ... ... ... ... ... ...
Other Types of Anthelmintic 0 0 0 0 1 0 0 0 0 0
Other Types of Anticoagulant 0 0 0 0 1 0 0 0 0 0
Lead 0 0 0 1 0 0 0 0 0 0
Topical Steroids 0 0 0 1 0 0 0 0 0 0
Selective Estrogen Receptor Modulators 0 0 0 0 0 0 0 0 1 0
Topical Antibiotic Preparations 0 0 0 1 0 0 0 0 0 0
Camphor 0 0 0 0 0 0 0 0 0 1
Spot Removers/Dry Cleaning Agents: Other Hydrocarbon and/or Non-Halogenated Containing 0 0 0 0 1 0 0 0 0 0
Creatine 0 0 0 0 1 0 0 0 0 0
Diphenhydramine Alone 4 0 4 46 26 9 0 12 10 3
Simple Asphyxiants 0 0 0 1 0 0 0 0 0 0
Disc Batteries: Lithium 0 0 0 1 0 0 0 0 0 0
Disinfectants: Hypochlorite 0 0 0 1 0 0 0 0 0 0
Energy Drinks: Caffeine Containing 0 0 0 1 0 0 0 0 0 0
Energy Drinks: Caffeine Only 0 0 0 1 0 0 0 0 0 0
Ephedrine 0 0 0 1 0 0 0 0 0 0
Ethylene Glycol 0 0 1 0 0 0 0 0 0 0
Ibuprofen with Hydrocodone 0 0 0 0 1 0 0 0 0 0
Scorpion Stings 0 0 0 0 1 0 0 0 0 0
Fluvoxamine 0 0 0 0 0 1 0 0 0 0
Freon and Other Propellants 0 0 0 1 0 0 0 0 0 0
Gasolines 0 0 0 1 0 0 0 0 0 0
Glass Cleaners: Other or Unknown Types of Household 0 0 0 1 0 0 0 0 0 0
Glucosamine 0 0 0 0 0 1 0 0 0 0
Group 6 Mushrooms: Hallucinogenics 0 0 0 1 0 0 0 0 0 0
Heparins 0 0 0 0 1 0 0 0 0 0
Hydrochloric Acid 0 0 0 0 0 1 0 0 0 0
Progestins 0 0 0 1 0 0 0 0 0 0
Hydrogen Peroxide 3% 0 0 0 1 0 0 0 0 0 0
oral Contraceptives 0 0 0 0 0 1 0 0 0 0

254 rows × 10 columns

Outcome percents


In [46]:
pd.concat([secondary_compare.sum().T,
           100*(secondary_compare.T).div(secondary_compare.sum().T.astype(float), axis=0).replace(np.nan, 0)], axis=1).rename(columns={0:'Total'})


Out[46]:
Total Death Death, indirect report Major effect Minor effect Moderate effect No effect Not followed, judged as nontoxic exposure (clinical effects not expected) Not followed, minimal clinical effects possible (no more than minor effect possible) Unable to follow, judged as a potentially toxic exposure Unrelated effect, the exposure was probably not responsible for the effect(s)
All calls 8106 0.666173 0.024673 3.084135 31.297804 17.838638 14.927214 1.394029 15.901801 12.324204 2.541327
Benzodiazepines 1144 1.660839 0.000000 5.594406 34.440559 32.954545 5.506993 0.087413 7.080420 11.101399 1.573427
Ethanol 546 0.915751 0.000000 4.029304 37.179487 30.219780 6.593407 0.000000 7.142857 12.820513 1.098901
Carisoprodol 315 0.952381 0.000000 4.444444 38.730159 34.603175 5.079365 0.317460 5.714286 9.206349 0.952381
Atypical Antipsychotics 218 0.917431 0.000000 10.550459 36.238532 34.403670 5.963303 0.000000 3.669725 5.504587 2.752294
Acetaminophen Alone, Adult 202 0.990099 0.495050 11.386139 30.198020 25.742574 11.386139 6.930693 5.940594 5.445545 1.485149
Other Types of Sedative/Hypnotic/Anti-Anxiety or Anti-Psychotic Drug 198 0.505051 0.000000 4.545455 36.868687 34.848485 4.545455 0.000000 9.595960 7.575758 1.515152
Ibuprofen 201 0.497512 0.000000 3.482587 38.308458 19.900498 16.417910 0.995025 12.935323 6.467662 0.995025
Other Types of Selective Serotonin Reuptake Inhibitor 175 0.000000 0.571429 5.714286 34.285714 32.000000 10.857143 0.000000 7.428571 6.857143 2.285714
Other Types of Muscle Relaxant 174 1.149425 0.000000 8.045977 28.160920 39.080460 8.045977 0.000000 5.747126 8.045977 1.724138
Cyclobenzaprine 158 1.265823 0.000000 3.797468 39.240506 29.746835 12.025316 0.000000 6.329114 5.063291 2.531646
Other Antihistamines Alone 151 1.324503 0.000000 5.298013 28.476821 35.099338 9.933775 0.662252 9.271523 9.271523 0.662252
Other Types of Anticonvulsant 141 0.709220 0.000000 9.219858 38.297872 29.078014 10.638298 0.000000 6.382979 3.546099 2.127660
Trazodone 139 2.158273 0.000000 6.474820 37.410072 33.812950 5.755396 0.000000 5.755396 8.633094 0.000000
Beta Blockers 136 1.470588 0.000000 5.882353 30.147059 37.500000 11.764706 0.000000 3.676471 6.617647 2.941176
Other Types of Antidepressant 102 1.960784 0.000000 11.764706 28.431373 38.235294 6.862745 0.000000 6.862745 2.941176 2.941176
Ethanol 546 0.915751 0.000000 4.029304 37.179487 30.219780 6.593407 0.000000 7.142857 12.820513 1.098901
Systemic Antibiotic Preparations 93 2.150538 0.000000 2.150538 35.483871 12.903226 12.903226 1.075269 21.505376 8.602151 3.225806
Methamphetamines 99 4.040404 0.000000 6.060606 29.292929 35.353535 6.060606 0.000000 6.060606 13.131313 0.000000
Diphenhydramine Alone 114 3.508772 0.000000 3.508772 40.350877 22.807018 7.894737 0.000000 10.526316 8.771930 2.631579
Gabapentin 105 0.000000 0.000000 6.666667 30.476190 29.523810 10.476190 0.000000 12.380952 7.619048 2.857143
Amphetamines and Related Compounds 81 0.000000 0.000000 11.111111 24.691358 49.382716 2.469136 1.234568 2.469136 4.938272 3.703704
Amitriptyline 77 0.000000 0.000000 3.896104 23.376623 55.844156 3.896104 0.000000 6.493506 3.896104 2.597403
Angiotensin Converting Enzyme Inhibitors 68 0.000000 0.000000 5.882353 30.882353 29.411765 20.588235 0.000000 2.941176 7.352941 2.941176
Acetaminophen in Combination with Other Drugs, Adult Formulations 64 0.000000 0.000000 7.812500 32.812500 23.437500 18.750000 0.000000 4.687500 10.937500 1.562500
Heroin 60 5.000000 0.000000 1.666667 33.333333 35.000000 5.000000 1.666667 5.000000 11.666667 1.666667
Other Types of Miscellaneous Prescription or Over the Counter Drug 52 0.000000 0.000000 1.923077 28.846154 34.615385 19.230769 0.000000 7.692308 5.769231 1.923077
Other Types of Tricyclic Antidepressant 58 1.724138 0.000000 10.344828 34.482759 43.103448 5.172414 0.000000 0.000000 0.000000 5.172414
Marijuana 56 0.000000 0.000000 8.928571 33.928571 35.714286 7.142857 0.000000 7.142857 5.357143 1.785714
Cocaine 57 3.508772 0.000000 3.508772 29.824561 40.350877 1.754386 1.754386 1.754386 10.526316 7.017544
... ... ... ... ... ... ... ... ... ... ... ...
Other Types of Anthelmintic 1 0.000000 0.000000 0.000000 0.000000 100.000000 0.000000 0.000000 0.000000 0.000000 0.000000
Other Types of Anticoagulant 1 0.000000 0.000000 0.000000 0.000000 100.000000 0.000000 0.000000 0.000000 0.000000 0.000000
Lead 1 0.000000 0.000000 0.000000 100.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000
Topical Steroids 1 0.000000 0.000000 0.000000 100.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000
Selective Estrogen Receptor Modulators 1 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 100.000000 0.000000
Topical Antibiotic Preparations 1 0.000000 0.000000 0.000000 100.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000
Camphor 1 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 100.000000
Spot Removers/Dry Cleaning Agents: Other Hydrocarbon and/or Non-Halogenated Containing 1 0.000000 0.000000 0.000000 0.000000 100.000000 0.000000 0.000000 0.000000 0.000000 0.000000
Creatine 1 0.000000 0.000000 0.000000 0.000000 100.000000 0.000000 0.000000 0.000000 0.000000 0.000000
Diphenhydramine Alone 114 3.508772 0.000000 3.508772 40.350877 22.807018 7.894737 0.000000 10.526316 8.771930 2.631579
Simple Asphyxiants 1 0.000000 0.000000 0.000000 100.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000
Disc Batteries: Lithium 1 0.000000 0.000000 0.000000 100.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000
Disinfectants: Hypochlorite 1 0.000000 0.000000 0.000000 100.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000
Energy Drinks: Caffeine Containing 1 0.000000 0.000000 0.000000 100.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000
Energy Drinks: Caffeine Only 1 0.000000 0.000000 0.000000 100.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000
Ephedrine 1 0.000000 0.000000 0.000000 100.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000
Ethylene Glycol 1 0.000000 0.000000 100.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000
Ibuprofen with Hydrocodone 1 0.000000 0.000000 0.000000 0.000000 100.000000 0.000000 0.000000 0.000000 0.000000 0.000000
Scorpion Stings 1 0.000000 0.000000 0.000000 0.000000 100.000000 0.000000 0.000000 0.000000 0.000000 0.000000
Fluvoxamine 1 0.000000 0.000000 0.000000 0.000000 0.000000 100.000000 0.000000 0.000000 0.000000 0.000000
Freon and Other Propellants 1 0.000000 0.000000 0.000000 100.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000
Gasolines 1 0.000000 0.000000 0.000000 100.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000
Glass Cleaners: Other or Unknown Types of Household 1 0.000000 0.000000 0.000000 100.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000
Glucosamine 1 0.000000 0.000000 0.000000 0.000000 0.000000 100.000000 0.000000 0.000000 0.000000 0.000000
Group 6 Mushrooms: Hallucinogenics 1 0.000000 0.000000 0.000000 100.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000
Heparins 1 0.000000 0.000000 0.000000 0.000000 100.000000 0.000000 0.000000 0.000000 0.000000 0.000000
Hydrochloric Acid 1 0.000000 0.000000 0.000000 0.000000 0.000000 100.000000 0.000000 0.000000 0.000000 0.000000
Progestins 1 0.000000 0.000000 0.000000 100.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000
Hydrogen Peroxide 3% 1 0.000000 0.000000 0.000000 100.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000
oral Contraceptives 1 0.000000 0.000000 0.000000 0.000000 0.000000 100.000000 0.000000 0.000000 0.000000 0.000000

254 rows × 11 columns

Secondary substances by reason


In [47]:
secondary_compare2 = matched.groupby('Reason').size()
secondary_compare2.name = 'All calls'

for i in pd.Series(secondary_substances.index).str.split('\(').str[0].str.strip().values:
    sub = matched[matched['Substance'].str.contains(i)].groupby('Reason').size()
    sub.name = i
    secondary_compare2 = pd.concat([secondary_compare2, sub], axis=1)
    
secondary_compare2.T.replace(np.nan, 0)


Out[47]:
Adverse reaction - Drug Adverse reaction - Food Adverse reaction - Other Intentional - Abuse Intentional - Misuse Intentional - Suspected suicide Intentional - Unknown Other - Contamination / tampering Other - Malicious Other - Withdrawal Unintentional - Bite / sting Unintentional - General Unintentional - Misuse Unintentional - Occupational Unintentional - Therapeutic error Unintentional - Unknown Unknown reason
All calls 666 1 9 754 777 2579 343 3 4 176 4 1388 157 1 1158 22 70
Benzodiazepines 44 0 1 118 76 643 77 0 1 18 1 95 14 0 44 5 10
Ethanol 13 0 1 71 38 336 28 1 0 8 0 38 5 0 5 0 4
Carisoprodol 6 0 0 43 31 168 29 0 0 4 0 20 3 0 9 1 2
Atypical Antipsychotics 14 0 0 11 10 135 9 0 1 3 0 14 1 0 14 0 6
Acetaminophen Alone, Adult 4 0 0 12 15 105 9 0 0 1 0 17 12 0 20 2 5
Other Types of Sedative/Hypnotic/Anti-Anxiety or Anti-Psychotic Drug 6 0 0 9 11 129 10 0 0 1 0 11 2 0 18 1 0
Ibuprofen 18 0 0 7 15 107 6 1 1 0 0 28 5 0 11 0 2
Other Types of Selective Serotonin Reuptake Inhibitor 12 0 0 2 6 113 9 1 0 1 0 15 0 0 14 2 0
Other Types of Muscle Relaxant 13 0 0 13 5 86 8 0 0 2 0 16 4 0 21 1 5
Cyclobenzaprine 9 0 0 12 9 91 7 0 0 0 0 18 2 0 9 1 0
Other Antihistamines Alone 13 0 0 9 7 89 8 0 0 1 0 12 1 0 9 0 2
Other Types of Anticonvulsant 11 0 1 5 11 71 7 0 0 1 0 11 2 0 17 3 1
Trazodone 6 0 0 8 7 91 6 1 0 3 0 7 2 0 5 2 2
Beta Blockers 6 0 0 1 5 75 2 0 0 0 0 11 1 0 32 3 0
Other Types of Antidepressant 9 0 0 2 1 65 5 0 0 3 0 4 2 0 6 3 2
Ethanol 13 0 1 71 38 336 28 1 0 8 0 38 5 0 5 0 4
Systemic Antibiotic Preparations 30 0 0 1 5 31 1 0 1 0 0 15 1 0 7 1 0
Methamphetamines 2 0 0 39 5 39 4 0 0 0 0 8 0 0 0 0 2
Diphenhydramine Alone 11 0 1 7 13 53 3 0 0 0 1 18 2 0 3 1 1
Gabapentin 7 0 0 5 6 50 1 0 0 0 0 9 4 0 19 0 5
Amphetamines and Related Compounds 2 0 0 13 3 41 7 0 0 1 0 10 0 0 2 1 1
Amitriptyline 7 0 1 2 4 49 4 0 0 0 0 3 1 0 6 0 0
Angiotensin Converting Enzyme Inhibitors 2 0 1 0 0 38 4 0 0 0 0 11 2 0 9 1 0
Acetaminophen in Combination with Other Drugs, Adult Formulations 2 0 0 2 6 37 4 0 0 1 0 5 1 0 5 1 0
Heroin 1 0 0 34 3 12 4 0 0 1 0 4 0 0 0 0 1
Other Types of Miscellaneous Prescription or Over the Counter Drug 8 0 0 0 1 21 1 0 0 0 0 9 0 0 11 1 0
Other Types of Tricyclic Antidepressant 4 0 0 6 2 33 6 0 0 0 0 4 0 0 0 0 3
Marijuana 1 0 0 19 3 25 4 0 0 0 0 4 0 0 0 0 1
Cocaine 0 0 0 18 3 22 5 0 0 3 0 4 0 0 1 0 1
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
Other Types of Anthelmintic 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0
Other Types of Anticoagulant 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0
Lead 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0
Topical Steroids 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0
Selective Estrogen Receptor Modulators 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0
Topical Antibiotic Preparations 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Camphor 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0
Spot Removers/Dry Cleaning Agents: Other Hydrocarbon and/or Non-Halogenated Containing 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0
Creatine 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0
Diphenhydramine Alone 11 0 1 7 13 53 3 0 0 0 1 18 2 0 3 1 1
Simple Asphyxiants 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0
Disc Batteries: Lithium 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0
Disinfectants: Hypochlorite 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0
Energy Drinks: Caffeine Containing 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0
Energy Drinks: Caffeine Only 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0
Ephedrine 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0
Ethylene Glycol 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0
Ibuprofen with Hydrocodone 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0
Scorpion Stings 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0
Fluvoxamine 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0
Freon and Other Propellants 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0
Gasolines 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0
Glass Cleaners: Other or Unknown Types of Household 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0
Glucosamine 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0
Group 6 Mushrooms: Hallucinogenics 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0
Heparins 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0
Hydrochloric Acid 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0
Progestins 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0
Hydrogen Peroxide 3% 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0
oral Contraceptives 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0

254 rows × 17 columns

Reasons by percent


In [48]:
pd.concat([secondary_compare2.sum().T,
           100*(secondary_compare2.T).div(secondary_compare2.sum().T.astype(float), axis=0).replace(np.nan, '')], axis=1).sort(0, ascending=False).rename(columns={0:'Total'})


Out[48]:
Total Adverse reaction - Drug Adverse reaction - Food Adverse reaction - Other Intentional - Abuse Intentional - Misuse Intentional - Suspected suicide Intentional - Unknown Other - Contamination / tampering Other - Malicious Other - Withdrawal Unintentional - Bite / sting Unintentional - General Unintentional - Misuse Unintentional - Occupational Unintentional - Therapeutic error Unintentional - Unknown Unknown reason
All calls 8112 8.210059 0.01232742 0.1109467 9.294872 9.578402 31.79241 4.228304 0.03698225 0.04930966 2.169625 0.04930966 17.11045 1.935404 0.01232742 14.27515 0.2712032 0.8629191
Benzodiazepines 1147 3.836094 0.08718396 10.28771 6.625981 56.05929 6.713165 0.08718396 1.569311 0.08718396 8.282476 1.220575 3.836094 0.4359198 0.8718396
Ethanol 548 2.372263 0.1824818 12.9562 6.934307 61.31387 5.109489 0.1824818 1.459854 6.934307 0.9124088 0.9124088 0.729927
Ethanol 548 2.372263 0.1824818 12.9562 6.934307 61.31387 5.109489 0.1824818 1.459854 6.934307 0.9124088 0.9124088 0.729927
Carisoprodol 316 1.898734 13.60759 9.810127 53.16456 9.177215 1.265823 6.329114 0.9493671 2.848101 0.3164557 0.6329114
Atypical Antipsychotics 218 6.422018 5.045872 4.587156 61.92661 4.12844 0.4587156 1.376147 6.422018 0.4587156 6.422018 2.752294
Acetaminophen Alone, Adult 202 1.980198 5.940594 7.425743 51.9802 4.455446 0.4950495 8.415842 5.940594 9.90099 0.990099 2.475248
Ibuprofen 201 8.955224 3.482587 7.462687 53.23383 2.985075 0.4975124 0.4975124 13.93035 2.487562 5.472637 0.9950249
Other Types of Sedative/Hypnotic/Anti-Anxiety or Anti-Psychotic Drug 198 3.030303 4.545455 5.555556 65.15152 5.050505 0.5050505 5.555556 1.010101 9.090909 0.5050505
Other Types of Selective Serotonin Reuptake Inhibitor 175 6.857143 1.142857 3.428571 64.57143 5.142857 0.5714286 0.5714286 8.571429 8 1.142857
Other Types of Muscle Relaxant 174 7.471264 7.471264 2.873563 49.42529 4.597701 1.149425 9.195402 2.298851 12.06897 0.5747126 2.873563
Cyclobenzaprine 158 5.696203 7.594937 5.696203 57.59494 4.43038 11.39241 1.265823 5.696203 0.6329114
Other Antihistamines Alone 151 8.609272 5.960265 4.635762 58.9404 5.298013 0.6622517 7.94702 0.6622517 5.960265 1.324503
Other Types of Anticonvulsant 141 7.801418 0.7092199 3.546099 7.801418 50.35461 4.964539 0.7092199 7.801418 1.41844 12.05674 2.12766 0.7092199
Trazodone 140 4.285714 5.714286 5 65 4.285714 0.7142857 2.142857 5 1.428571 3.571429 1.428571 1.428571
Beta Blockers 136 4.411765 0.7352941 3.676471 55.14706 1.470588 8.088235 0.7352941 23.52941 2.205882
Diphenhydramine Alone 114 9.649123 0.877193 6.140351 11.40351 46.49123 2.631579 0.877193 15.78947 1.754386 2.631579 0.877193 0.877193
Diphenhydramine Alone 114 9.649123 0.877193 6.140351 11.40351 46.49123 2.631579 0.877193 15.78947 1.754386 2.631579 0.877193 0.877193
Diphenhydramine Alone 114 9.649123 0.877193 6.140351 11.40351 46.49123 2.631579 0.877193 15.78947 1.754386 2.631579 0.877193 0.877193
Gabapentin 106 6.603774 4.716981 5.660377 47.16981 0.9433962 8.490566 3.773585 17.92453 4.716981
Other Types of Antidepressant 102 8.823529 1.960784 0.9803922 63.72549 4.901961 2.941176 3.921569 1.960784 5.882353 2.941176 1.960784
Methamphetamines 99 2.020202 39.39394 5.050505 39.39394 4.040404 8.080808 2.020202
Systemic Antibiotic Preparations 93 32.25806 1.075269 5.376344 33.33333 1.075269 1.075269 16.12903 1.075269 7.526882 1.075269
Amphetamines and Related Compounds 81 2.469136 16.04938 3.703704 50.61728 8.641975 1.234568 12.34568 2.469136 1.234568 1.234568
Amitriptyline 77 9.090909 1.298701 2.597403 5.194805 63.63636 5.194805 3.896104 1.298701 7.792208
Caffeine 74 8.108108 6.756757 9.459459 31.08108 5.405405 20.27027 1.351351 16.21622 1.351351
Angiotensin Converting Enzyme Inhibitors 68 2.941176 1.470588 55.88235 5.882353 16.17647 2.941176 13.23529 1.470588
Acetaminophen in Combination with Other Drugs, Adult Formulations 64 3.125 3.125 9.375 57.8125 6.25 1.5625 7.8125 1.5625 7.8125 1.5625
Heroin 60 1.666667 56.66667 5 20 6.666667 1.666667 6.666667 1.666667
Other Types of Tricyclic Antidepressant 58 6.896552 10.34483 3.448276 56.89655 10.34483 6.896552 5.172414
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
Valerian 1 100
Wall/Floor/Tile/All-Purpose Cleaning Agents: Anionics or Nonionics 1 100
Other Types of Monoamine Oxidase Inhibitor 1 100
Zonisamide 1 100
Aminophylline or Theophylline 1 100
Antispasmodics: Other Types 1 100
Other Types of Foreign Body, Toy, or Miscellaneous Substance 1 100
Tricyclic Antidepressants 1 100
Automotive Products: Methanol 1 100
Automotive Products: Hydrocarbons 1 100
Unknown Types of Hydrocarbon 1 100
Antacids: Salicylate-Containing 1 100
Unknown Types of Cardiovascular Drug 1 100
Antihistamine and/or Decongestant with Phenylpropanolamine and Other Opioid 1 100
Other Types of Serotonin Norepinephrine Reuptake Inhibitor 1 100
Miscellaneous Polishes and Waxes 1 100
Miscellaneous Cleaning Agents: Isopropanol 1 100
Miscellaneous Cleaning Agents: Acids 1 100
Other Types of Vitamin 1 100
Metal Fume Fever 1 100
Mercury, Elemental 1 100
Magnesium and Magnesium Salts 1 100
Long-Acting Anticoagulant Rodenticides 1 100
gamma-Hydroxybutyric Acid including Analogs or Precursors 1 100
Multiple Vitamin Tablets: Pediatric Formulations with Iron 1 100
Bleaches: Hypochlorite 1 100
Shampoos 1 100
Toys 1 100
Antihistamine and/or Decongestant with Phenylpropanolamine without Opioid 1 100
oral Contraceptives 1 100

254 rows × 18 columns

Extras


In [49]:
matched_death = matched.dropna(subset=['Medical Outcome'])[matched['Medical Outcome'].dropna().str.contains('Death')]

In [50]:
opioid_deaths_expanded = (searchcodes.set_index('Opioid name')['Code number']
             .apply(lambda x: matched[matched['Medical Outcome']
             .str.contains('Death') & (matched['Substance'].str.contains(x))])
             .replace(0, np.nan).dropna().reset_index().rename(columns={'Code number':'Deaths'}))

In [51]:
opioid_deaths_expanded = (opioid_deaths_expanded[opioid_deaths_expanded['Deaths'].str.len() != 0]
.set_index('Opioid name')['Deaths'].apply(lambda x: x['Substance'].values))

In [52]:
opioid_deaths_expanded = pd.Series(np.concatenate(opioid_deaths_expanded.values),
                                   index=np.repeat(opioid_deaths_expanded.index.values,
                                                   opioid_deaths_expanded.str.len()))

In [53]:
secondary_counts = (pd.Series(np.concatenate(opioid_deaths_expanded.str.split(' ; ').apply(np.array).values))
 .str.split('[').str[0].str.split(' - ').apply(pd.Series).apply(lambda x: x.str.strip())).groupby(0).size().order(ascending=False)

In [54]:
opioid_deaths_expanded = (pd.Series(np.concatenate(opioid_deaths_expanded.str.split(' ; ').apply(np.array).values),
          index=np.repeat(opioid_deaths_expanded.index.values, opioid_deaths_expanded.str.split(' ; ')
                          .str.len())).str.split('[').str[0].str.split(' - ').apply(pd.Series))

In [55]:
opioid_deaths_expanded[0] = opioid_deaths_expanded[0].str.strip()

In [56]:
opioid_deaths_expanded = opioid_deaths_expanded.reset_index().rename(columns={'index' : 'primary',
                         0 : 'secondary'}).groupby(['primary', 'secondary']).size().reset_index()

In [57]:
len(matched[matched['Substance'].str.contains('Benzodiazepines')])


Out[57]:
1147

In [58]:
len(matched[(matched['Substance'].str.contains('Benzodiazepines')) & (matched['Reason'].str.contains('[Ss]uicide'))])


Out[58]:
643

In [59]:
benzo = matched[matched['Substance'].str.contains('Benzodiazepines')]
ethanol = matched[matched['Substance'].str.contains('Ethanol')]

benzo_compare = (pd.concat([benzo.groupby('Medical Outcome').size(),
                            matched.groupby('Medical Outcome').size(),
                            ethanol.groupby('Medical Outcome').size()], axis=1).rename(columns={0:'Benzodiazepine', 1:'All Opioids', 2:'Ethanol'}))

benzo_compare


Out[59]:
Benzodiazepine All Opioids Ethanol
Death 19 54 5
Death, indirect report NaN 2 NaN
Major effect 64 250 22
Minor effect 394 2537 203
Moderate effect 377 1446 165
No effect 63 1210 36
Not followed, judged as nontoxic exposure (clinical effects not expected) 1 113 NaN
Not followed, minimal clinical effects possible (no more than minor effect possible) 81 1289 39
Unable to follow, judged as a potentially toxic exposure 127 999 70
Unrelated effect, the exposure was probably not responsible for the effect(s) 18 206 6

In [60]:
benz_reason = matched[matched['Substance'].str.contains('0007000')].groupby('Reason').size()

benz_reason/benz_reason.sum()*100


Out[60]:
Reason
Adverse reaction - Drug               3.836094
Adverse reaction - Other              0.087184
Intentional - Abuse                  10.287707
Intentional - Misuse                  6.625981
Intentional - Suspected suicide      56.059285
Intentional - Unknown                 6.713165
Other - Malicious                     0.087184
Other - Withdrawal                    1.569311
Unintentional - Bite / sting          0.087184
Unintentional - General               8.282476
Unintentional - Misuse                1.220575
Unintentional - Therapeutic error     3.836094
Unintentional - Unknown               0.435920
Unknown reason                        0.871840
dtype: float64

In [60]: