Scripts to create a dataset from Redcap outputs to use for a PLS-DA classification.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

54 lines
1.8 KiB

# -*- coding: utf-8 -*-
"""
Created on Fri Apr 2 10:57:40 2021
@author: Dijkhofmf
"""
import os
import pandas as pd
pd.options.mode.chained_assignment = None # default='warn'
Path = r'I:\Mike Dijkhof\Connecare MGP\Data\FinalFiles'
os.chdir(Path)
FilenameOutc = 'SurgAdmComp.csv'
FilenameSACM = 'DataSACM.csv'
FilenameComplet = 'Complete.csv'
DFComp = pd.DataFrame(pd.read_csv(FilenameOutc))
DFComp = DFComp.set_index('Study ID')
DFSACM = pd.DataFrame(pd.read_csv(FilenameSACM))
DFSACM = DFSACM.set_index('Study ID')
DFComplet = pd.DataFrame(pd.read_csv(FilenameComplet))
DFComplet = DFComplet.set_index('Study ID')
Startdate = pd.to_datetime(DFSACM['Start date Fitbit']).dt.date
Enddate = pd.to_datetime(DFSACM['End date Fitbit']).dt.date
DFDates = pd.DataFrame()
DFDates['Study ID'] = DFComp.index
DFDates = DFDates.set_index('Study ID')
DFDates['Start'] = Startdate
DFDates['Surgery'] = pd.to_datetime(DFComp['Date of surgery']).dt.date
DFDates['Preop'] = DFDates['Surgery'] - DFDates['Start']
DFDates['Discharge'] = pd.to_datetime(DFComp['Date of hospital discharge']).dt.date
DFDates['LOS'] = DFDates['Discharge'] - DFDates['Surgery']
DFDates['St2Dis'] = DFDates['Discharge'] - DFDates['Start']
DFDates['First Comp'] = pd.to_datetime(DFComp['Date first complication at home']).dt.date
DFDates['T2C'] = DFDates['First Comp'] - DFDates['Discharge']
DFDates['First Read'] = pd.to_datetime(DFComp['Date (first) readmission']).dt.date
DFDates['T2R'] = DFDates['First Read'] - DFDates['Discharge']
DFDates['Sec Read'] = pd.to_datetime(DFComp['Date second readmission']).dt.date
DFDates['T2SR'] = DFDates['Sec Read'] - DFDates['Discharge']
DFDates['End'] = Enddate
DFDates['Length'] = DFDates['End'] - DFDates['Start']
DFDates = DFDates[DFComplet['Has patient completed study?']=='Yes']
DFDates.to_csv('Dates.csv')