add_grouping.py 916 B

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