Created
August 16, 2023 14:42
-
-
Save tashrifbillah/7bf587fd16a50cb79f489b5f78090e36 to your computer and use it in GitHub Desktop.
Format REDCap data for REDCap cloud
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 sys | |
import pandas as pd | |
df=pd.read_csv(sys.argv[1],dtype=str) | |
df1=df.copy() | |
df1.rename(columns={'chric_record_id':'participant_id'},inplace=True) | |
df1["redcap_system_data_format_version"]=1 | |
df1["redcap_subject_screening_number"]=df1['participant_id'] | |
df1['redcap_study']=[ s[:2] for s in df1['participant_id'].values ] | |
df1.drop(['redcap_data_access_group','redcap_survey_identifier'],inplace=True,axis=1) | |
reindex=["redcap_system_data_format_version","participant_id","redcap_subject_screening_number","redcap_study","redcap_event_name"]+list(df1.columns[2:-3]) | |
df1=df1[reindex] | |
df1.to_csv(sys.argv[2], index=False) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment