I have an excel file with Patient names and Dates. For example:
Column A=[1000, 1000, 1001, 1001, 1001, 1002, 1002, 1002, 1002]
Column B=['03/12/2009', '03/12/2009', '04/01/2011', '05/01/2010', '08/02/2011', '10/03/2012', '05/12/2010', '07/02/2011', '09/03/2012', '14/02/2013']
For each patient name, I want to calculate the total length of time between the first and final date. I thought to perform this via a pandas df, but I can't complete my code to match the total time for each patient. This is what I have tried so far:
Patient_Dates = pd.read_excel(r'C:UsersPycharmProjectsData.xlsx',
sheet_name='Sheet 2', header=0, na_values=['NA'], usecols = "B:C")
Patient_Dates_new=Patient_Dates.iloc[3:len(Patient_Dates)]
Patient_Dates_new.columns = ['Patient_ID','Dates']
How can I calculate the total time in days for each patient? Here below is part of my excel file.
question from:
https://stackoverflow.com/questions/65871362/how-to-calculate-total-time-difference-for-rows-with-same-name-using-a-pandas-da 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…