import xlrd
import pandas
import matplotlib.pyplot as plt
import datetime
%pylab inline
Populating the interactive namespace from numpy and matplotlib
#Synapse Internal Project
#clinical meta data
#clinical_meta_data_file = "/Users/abhishek/apratap_bt/projects/RA/AIR_Clinical_Data.xls"
clinical_meta_data_file = "/Users/apratap/Desktop/AIR_Clinical_Data.xls"
xl_workbook = pandas.ExcelFile(clinical_meta_data_file)
xl_workbook.sheet_names
[u'demo', u'drugs', u'Drug Data Dictionary']
patient_metadata.collectiondate.astype(str)
--------------------------------------------------------------------------- TypeError Traceback (most recent call last) <ipython-input-31-b059d0a8e301> in <module>() ----> 1 patient_metadata.collectiondate.astype(str) /Users/apratap/anaconda/python.app/Contents/lib/python2.7/site-packages/pandas/core/series.pyc in astype(self, dtype) 932 values = com._possibly_cast_to_datetime(self.values,dtype) 933 else: --> 934 values = com._astype_nansafe(self.values, dtype) 935 return self._constructor(values, index=self.index, name=self.name, 936 dtype=values.dtype) /Users/apratap/anaconda/python.app/Contents/lib/python2.7/site-packages/pandas/core/common.pyc in _astype_nansafe(arr, dtype, copy) 1641 return arr.view(dtype) 1642 elif dtype != _NS_DTYPE: -> 1643 raise TypeError("cannot astype a datetimelike from [%s] to [%s]" % (arr.dtype,dtype)) 1644 return arr.astype(_NS_DTYPE) 1645 elif is_timedelta64_dtype(arr): TypeError: cannot astype a datetimelike from [datetime64[ns]] to [|S0]
for index,row in patient_metadata.iterrows():
for x in row.values:
print x
break
RA10-0014 2010-12-28 00:00:00 2010-12-29 00:00:00 53.0 Female 0.1 349.0
patient_metadata[['age','sex','RF']].boxplot(by='sex',figsize=(10,5))
plt.show()
from pandas.tools.plotting import scatter_matrix
result = scatter_matrix(patient_metadata[['age','sex','RF','CRP','date']],figsize=(14,10),diagonal='kde' )
patient_drugs = xl_workbook.parse('drugs')
patient_drugs.ix[:,0:10].head()
qstkitid | collectiondate | date | simponi | rituxan | remicade | orencia | kineret | humira | enbrel | |
---|---|---|---|---|---|---|---|---|---|---|
0 | RA10-0014 | 2010-12-28 00:00:00 | 2010-11-15 00:00:00 | 0 | 0 | 0 | 0 | 0 | 1 | 0 |
1 | RA10-0014 | 2010-12-28 00:00:00 | 2010-12-15 00:00:00 | 0 | 0 | 0 | 0 | 0 | 1 | 0 |
2 | RA10-0018 | 2010-10-27 00:00:00 | 2010-09-15 00:00:00 | 0 | 0 | 0 | 0 | 0 | 0 | 1 |
3 | RA10-0018 | 2010-10-27 00:00:00 | 2010-10-15 00:00:00 | 0 | 0 | 0 | 0 | 0 | 0 | 1 |
4 | RA10-0025 | 2010-11-08 00:00:00 | 2010-10-15 00:00:00 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
full_drug_names = xl_workbook.parse('Drug Data Dictionary')
full_drug_names
Drug column | Drug name | |
---|---|---|
0 | arava | Leflunomide |
1 | auranofn | Auranofin |
2 | azathiop | Azathioprine |
3 | azulfidn | Sulfasalazine |
4 | cellcept | Mycophenolate |
5 | cyclospr | Cyclosporin |
6 | cytxin | Cyclophosphamide |
7 | goldinj | Injectable Gold |
8 | minocycl | Minocycline |
9 | mtxinj | Methotrexate injectable |
10 | mtxpo | Methotrexate oral |
11 | penamine | Penicillamine |
12 | plaquinl | Hydroxychloroquine |
13 | actmra | Tocilizumab |
14 | cimzia | Certolizumab |
15 | enbrel | Etanercept |
16 | humira | Adalimumab |
17 | kineret | Anakinra |
18 | orencia | Abatacept |
19 | remicade | Infliximab |
20 | rituxan | Rituxumab |
21 | simponi | Golimumab |