In [ ]:
import pandas as pd
import numpy as np
import json as js
import urllib2 as ulib
import simplejson
import matplotlib.pyplot as plt

In [ ]:
# try reading with pandas... error??
fdaquery=pd.read_json("http://api.fda.gov/drug/event.json?search=patient.drug.openfda.pharm_class_epc:\"nonsteroidal+anti-inflammatory+drug\"&count=patient.reaction.reactionmeddrapt.exact")

In [ ]:
fdaquery_request=ulib.Request("http://api.fda.gov/drug/event.json?search=patient.drug.openfda.pharm_class_epc:\"nonsteroidal+anti-inflammatory+drug\"&count=patient.reaction.reactionmeddrapt.exact")

In [ ]:
opener = ulib.build_opener()
f = opener.open(fdaquery_request)
fda_data=simplejson.load(f)

In [88]:
# get the list of adverse events
fda_list=fda_data['results']

In [89]:
fda_list


Out[89]:
[{'count': 15586, 'term': 'NAUSEA'},
 {'count': 13792, 'term': 'DYSPNOEA'},
 {'count': 12829, 'term': 'MYOCARDIAL INFARCTION'},
 {'count': 12772, 'term': 'PAIN'},
 {'count': 12592, 'term': 'DIZZINESS'},
 {'count': 12588, 'term': 'DRUG INEFFECTIVE'},
 {'count': 11128, 'term': 'HEADACHE'},
 {'count': 11076, 'term': 'FATIGUE'},
 {'count': 10565, 'term': 'FLUSHING'},
 {'count': 10184, 'term': 'VOMITING'},
 {'count': 10044, 'term': 'DIARRHOEA'},
 {'count': 9271, 'term': 'ASTHENIA'},
 {'count': 8763, 'term': 'CEREBROVASCULAR ACCIDENT'},
 {'count': 8650, 'term': 'CHEST PAIN'},
 {'count': 8566, 'term': 'PRURITUS'},
 {'count': 8155, 'term': 'ARTHRALGIA'},
 {'count': 7779, 'term': 'FALL'},
 {'count': 7596, 'term': 'PAIN IN EXTREMITY'},
 {'count': 7342, 'term': 'OEDEMA PERIPHERAL'},
 {'count': 7174, 'term': 'ANXIETY'},
 {'count': 7131, 'term': 'PYREXIA'},
 {'count': 6858, 'term': 'HYPERTENSION'},
 {'count': 6489, 'term': 'DEPRESSION'},
 {'count': 6486, 'term': 'RENAL FAILURE ACUTE'},
 {'count': 6462, 'term': 'MALAISE'},
 {'count': 6436, 'term': 'RASH'},
 {'count': 6400, 'term': 'ANAEMIA'},
 {'count': 6315, 'term': 'BACK PAIN'},
 {'count': 5999, 'term': 'PNEUMONIA'},
 {'count': 5997, 'term': 'HYPOTENSION'},
 {'count': 5731, 'term': 'WEIGHT DECREASED'},
 {'count': 5667, 'term': 'ABDOMINAL PAIN'},
 {'count': 5662, 'term': 'INSOMNIA'},
 {'count': 5472, 'term': 'PARAESTHESIA'},
 {'count': 5146, 'term': 'BLOOD GLUCOSE INCREASED'},
 {'count': 5114, 'term': 'ABDOMINAL PAIN UPPER'},
 {'count': 4818, 'term': 'DRUG INTERACTION'},
 {'count': 4767, 'term': 'MYALGIA'},
 {'count': 4669, 'term': 'COUGH'},
 {'count': 4607, 'term': 'RENAL FAILURE'},
 {'count': 4606, 'term': 'ERYTHEMA'},
 {'count': 4482, 'term': 'GASTROINTESTINAL HAEMORRHAGE'},
 {'count': 4463, 'term': 'FEELING ABNORMAL'},
 {'count': 4441, 'term': 'CARDIAC FAILURE CONGESTIVE'},
 {'count': 4409, 'term': 'CONSTIPATION'},
 {'count': 4402, 'term': 'DEATH'},
 {'count': 4392, 'term': 'DEHYDRATION'},
 {'count': 4343, 'term': 'CONFUSIONAL STATE'},
 {'count': 4296, 'term': 'SOMNOLENCE'},
 {'count': 4276, 'term': 'HAEMOGLOBIN DECREASED'},
 {'count': 4270, 'term': 'PULMONARY EMBOLISM'},
 {'count': 4081, 'term': 'ATRIAL FIBRILLATION'},
 {'count': 3978, 'term': 'CONDITION AGGRAVATED'},
 {'count': 3963, 'term': 'BLOOD PRESSURE INCREASED'},
 {'count': 3961, 'term': 'HYPERHIDROSIS'},
 {'count': 3936, 'term': 'LOSS OF CONSCIOUSNESS'},
 {'count': 3902, 'term': 'WEIGHT INCREASED'},
 {'count': 3862, 'term': 'HYPOAESTHESIA'},
 {'count': 3855, 'term': 'MUSCLE SPASMS'},
 {'count': 3682, 'term': 'DEEP VEIN THROMBOSIS'},
 {'count': 3655, 'term': 'GAIT DISTURBANCE'},
 {'count': 3629, 'term': 'FEELING HOT'},
 {'count': 3620, 'term': 'INJURY'},
 {'count': 3603, 'term': 'DECREASED APPETITE'},
 {'count': 3598, 'term': 'TREMOR'},
 {'count': 3477, 'term': 'URINARY TRACT INFECTION'},
 {'count': 3433, 'term': 'SYNCOPE'},
 {'count': 3341, 'term': 'CORONARY ARTERY DISEASE'},
 {'count': 3316, 'term': 'HYPERSENSITIVITY'},
 {'count': 3170, 'term': 'DYSPEPSIA'},
 {'count': 3156, 'term': 'URTICARIA'},
 {'count': 3155, 'term': 'PALPITATIONS'},
 {'count': 3067, 'term': 'CONVULSION'},
 {'count': 3056, 'term': 'VISION BLURRED'},
 {'count': 2986, 'term': 'BLOOD CREATININE INCREASED'},
 {'count': 2955, 'term': 'MUSCULAR WEAKNESS'},
 {'count': 2943, 'term': 'INJECTION SITE PAIN'},
 {'count': 2939, 'term': 'GASTROOESOPHAGEAL REFLUX DISEASE'},
 {'count': 2909, 'term': 'DIABETES MELLITUS'},
 {'count': 2831, 'term': 'ABDOMINAL DISCOMFORT'},
 {'count': 2757, 'term': 'CHEST DISCOMFORT'},
 {'count': 2751, 'term': 'CARDIAC DISORDER'},
 {'count': 2702, 'term': 'CARDIAC ARREST'},
 {'count': 2683, 'term': 'HAEMORRHAGE'},
 {'count': 2665, 'term': 'CONTUSION'},
 {'count': 2611, 'term': 'CHILLS'},
 {'count': 2609, 'term': 'HEART RATE INCREASED'},
 {'count': 2585, 'term': 'TRANSIENT ISCHAEMIC ATTACK'},
 {'count': 2566, 'term': 'ALANINE AMINOTRANSFERASE INCREASED'},
 {'count': 2557, 'term': 'OVERDOSE'},
 {'count': 2505, 'term': 'THROMBOCYTOPENIA'},
 {'count': 2496, 'term': 'SEPSIS'},
 {'count': 2466, 'term': 'CARDIOVASCULAR DISORDER'},
 {'count': 2461, 'term': 'ARTHRITIS'},
 {'count': 1888, 'term': 'ASPARTATE AMINOTRANSFERASE INCREASED'},
 {'count': 1474, 'term': 'EMOTIONAL DISTRESS'},
 {'count': 1448, 'term': 'DYSPHAGIA'},
 {'count': 1448, 'term': 'BLOOD CHOLESTEROL INCREASED'},
 {'count': 1428, 'term': 'GENERAL PHYSICAL HEALTH DETERIORATION'},
 {'count': 1424, 'term': 'THROMBOSIS'}]

In [87]:
from operator import itemgetter
map(itemgetter('count'), fda_list)


Out[87]:
[15586,
 13792,
 12829,
 12772,
 12592,
 12588,
 11128,
 11076,
 10565,
 10184,
 10044,
 9271,
 8763,
 8650,
 8566,
 8155,
 7779,
 7596,
 7342,
 7174,
 7131,
 6858,
 6489,
 6486,
 6462,
 6436,
 6400,
 6315,
 5999,
 5997,
 5731,
 5667,
 5662,
 5472,
 5146,
 5114,
 4818,
 4767,
 4669,
 4607,
 4606,
 4482,
 4463,
 4441,
 4409,
 4402,
 4392,
 4343,
 4296,
 4276,
 4270,
 4081,
 3978,
 3963,
 3961,
 3936,
 3902,
 3862,
 3855,
 3682,
 3655,
 3629,
 3620,
 3603,
 3598,
 3477,
 3433,
 3341,
 3316,
 3170,
 3156,
 3155,
 3067,
 3056,
 2986,
 2955,
 2943,
 2939,
 2909,
 2831,
 2757,
 2751,
 2702,
 2683,
 2665,
 2611,
 2609,
 2585,
 2566,
 2557,
 2505,
 2496,
 2466,
 2461,
 1888,
 1474,
 1448,
 1448,
 1428,
 1424]

In [ ]: