1234567891011121314151617181920 |
- import pandas as pd
- # Load the first CSV file
- df = pd.read_csv(r"E:\2024_Ruthe_SND\output\Final_Quantitative_output\data_summary.csv")
- # Load the second CSV file
- cluster_df = pd.read_csv("C:\\Users\\aswen\\Desktop\\Code\\Behavioural_analysis\\output\\final_zscored_clustered.csv")
- # Merge the 'Sham' column from cluster_df to df based on 'subjectID' and 'Study ID'
- df = df.merge(cluster_df[['Study ID', 'Sham']], left_on='subjectID', right_on='Study ID', how='left')
- # Rename 'Sham' column to 'Group' and replace True/False values with 'sham'/'Stroke'
- df['Group'] = df['Sham'].apply(lambda x: 'sham' if x == True else 'Stroke')
- # Save the updated DataFrame to a new CSV file
- output_file_path = r"E:\2024_Ruthe_SND\output\Final_Quantitative_output\Quantitative_output_adjusted.csv"
- df.to_csv(output_file_path, index=False)
- print("Adjusted results saved successfully at:", output_file_path)
|