Created
January 12, 2022 18:18
-
-
Save tashrifbillah/ee3bfdd631d0cbe6bf433f28fcebf2d9 to your computer and use it in GitHub Desktop.
Combines subject-level DPdash comptabile files to a project-level DPdash file
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import pandas as pd | |
import sys | |
from os.path import abspath | |
import numpy as np | |
COMBINED_STUDY='files' | |
COMBINED_SUBJECT='combined' | |
files= sorted(sys.argv[1:]) | |
# read Kevin's dataframe | |
df= pd.read_csv(files[0]) | |
# replace day column, append subject_id column | |
dfnew= df.copy() | |
cases=[] | |
for i,f in enumerate(files): | |
print(f) | |
# example file name LA-LA00012-flowcheck-day1to1.csv | |
cases.append(f.split('-')[1]) | |
df= pd.read_csv(f) | |
dfnew.loc[i]=df.loc[0] | |
cases=np.unique(cases) | |
L= len(cases) | |
# populate day column | |
dfnew['day']= [i+1 for i in range(L)] | |
# populate subject_id column | |
dfnew['subject_id']= cases | |
outfile= f'{COMBINED_STUDY}-{COMBINED_SUBJECT}-flowcheck-day1to9999.csv' | |
dfnew.to_csv(outfile, index=False) | |
dfmeta= pd.DataFrame(columns=['Subject ID','Active','Consent','Study']) | |
dfmeta['Subject ID']= cases | |
dfmeta['Active']= [1]*L | |
dfmeta['Consent']= ['-']*L | |
dfmeta['Study']= [COMBINED_STUDY]*L | |
# append combined row | |
dfmeta.loc[L]=[COMBINED_SUBJECT,1,'-',COMBINED_STUDY] | |
dfmeta.to_csv(f'{COMBINED_STUDY}_metadata.csv', index=False) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment