-
Notifications
You must be signed in to change notification settings - Fork 0
/
rr.py
40 lines (25 loc) · 916 Bytes
/
rr.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#Risk Ratio Calculation
# -*- coding: utf-8 -*-
"""
Created on Sat Apr 08 19:20:20 2017
@author: OnoTation
"""
#import the library
import pandas as pd
#read the csv as df
df = pd.read_csv('file:///C:/Users/OnoTation/Desktop/Internship/tableforpython.csv')
df.values
#assemlbe unique age groups
ages= df.AgeGroups.unique()
#group the dataframes by agegroup, factor and cancer and calculate the frequency distribution
grp = df.groupby(['AgeGroups','Factor','Cancer']).Frequency.sum()
counts = grp.unstack(level=[2])
#risk with or without cancer
counts['sumwwoCancer']= counts['No']+counts['Yes']
test = counts['cumInci']=((counts['Yes']/counts['sumwwoCancer'])*100)
test1 = test.unstack(level=[1])
#RR,ARP,PF calculation
test1['RR'] = (test1['w-statin']/test1['wo-statin'])
test1['ARP']= (test1['RR']-1/test1['RR'])
test1['PF']= (1-test1['RR'])
print test1