Skip to content

Instantly share code, notes, and snippets.

@tashrifbillah
Created August 16, 2023 14:42
Show Gist options
  • Save tashrifbillah/7bf587fd16a50cb79f489b5f78090e36 to your computer and use it in GitHub Desktop.
Save tashrifbillah/7bf587fd16a50cb79f489b5f78090e36 to your computer and use it in GitHub Desktop.
Format REDCap data for REDCap cloud
#!/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