abuer commited on
Commit
87d54b5
·
verified ·
1 Parent(s): 8b49084

Upload index.py

Browse files
Files changed (1) hide show
  1. project/index.py +32 -0
project/index.py ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import pandas as pd
2
+ import numpy as np
3
+
4
+ def invoke(_input):
5
+ if _input is None:
6
+ return 'no _file provided'
7
+ columns = ['trialno','exclude','allocation','receive_allocation','followup','analysis']
8
+ df = pd.read_excel(_input['file'])
9
+ if sum(np.isin(columns, df.columns)) < 6:
10
+ return '文件中必须包含这些列:trialno,exclude,allocation,receive_allocation,followup,analysis'
11
+ res = {}
12
+ res['1_enroll'] = df['trialno'].count()
13
+ res['2_exclude'] = df['exclude'].count()
14
+ res['2_exclude_reason'] = dict(df['exclude'].value_counts())
15
+ res['3_randomized'] = res['1_enroll'] - res['2_exclude']
16
+ allo = df['allocation'].dropna().unique()
17
+ for i in allo:
18
+ a = f'4_allocation_{i}'
19
+ b_1 = f'4_allocation_{i}_received'
20
+ b_2 = f'4_allocation_{i}_refused'
21
+ c = f'5_stop_followup_{i}'
22
+ d = f'6_analyzed_{i}'
23
+ e = f'6_exclude_from_analysis_{i}'
24
+ res[a] = df.query(f'allocation == "{i}"').allocation.count()
25
+ res[b_1] = res[a] - df.query(f'allocation == "{i}"').receive_allocation.count()
26
+ res[b_2] = dict(df.query(f'allocation == "{i}"').receive_allocation.value_counts())
27
+ res[c] = dict(df.query(f'allocation == "{i}"').followup.value_counts())
28
+ res[d] = df.query(f'allocation == "{i}" & analysis == "analyzed"').analysis.count()
29
+ res[e] = dict(df.query(f'allocation == "{i}" & analysis != "analyzed"').analysis.value_counts())
30
+ for key, value in res.items():
31
+ res.update({key:str(value)})
32
+ return res