123456789101112131415161718192021222324 |
- import pandas as pd
- # Define paths to the CSV files
- csv_path_old = r"C:\Users\aswen\Desktop\Code\2024_Ruthe_SND\output\Quantitative_outputs\old\Quantitative_results_from_dwi_processing.csv"
- csv_path_new = r"C:\Users\aswen\Desktop\Code\2024_Ruthe_SND\output\Quantitative_outputs\Quantitative_results_from_dwi_processing.csv"
- output_path = r"C:\Users\aswen\Desktop\Code\2024_Ruthe_SND\output\Quantitative_outputs\Merged_Quantitative_results_from_dwi_processing.csv"
- # Load both CSVs into pandas DataFrames
- df_old = pd.read_csv(csv_path_old)
- df_new = pd.read_csv(csv_path_new)
- # Rename the 'Value' column in the old DataFrame to 'Value_with_wm_mask'
- df_old = df_old.rename(columns={'Value': 'Value_with_wm_mask'})
- # Columns to merge on
- merge_columns = ['subjectID', 'timePoint', 'merged_timepoint', 'Qtype', 'mask_name', 'dialation_amount', 'Group']
- # Merge the DataFrames on the specified columns
- df_merged = pd.merge(df_old, df_new, on=merge_columns)
- # Save the merged DataFrame to a new CSV file
- df_merged.to_csv(output_path, index=False)
- print(f"Merged CSV saved to {output_path}")
|