create_stroke_mri_list.py 1.3 KB

1234567891011121314151617181920212223242526272829303132333435
  1. # -*- coding: utf-8 -*-
  2. """
  3. Created on Fri Jul 5 16:31:58 2024
  4. @author: arefks
  5. """
  6. import os
  7. import pandas as pd
  8. # Get the directory where the code file is located
  9. code_dir = os.path.dirname(os.path.abspath(__file__))
  10. # Get the parent directory of the code directory
  11. parent_dir = os.path.dirname(code_dir)
  12. # Read the behavior data CSV file into a Pandas DataFrame
  13. input_file_path_behavior = os.path.join(parent_dir, 'input', 'Merged_behaviour_data.csv')
  14. df_b = pd.read_csv(input_file_path_behavior)
  15. # Read the MRI data CSV file into a Pandas DataFrame
  16. input_file_path_mri = os.path.join(parent_dir, 'output', "MRI", 'MRI_files_overview.csv')
  17. df_mri = pd.read_csv(input_file_path_mri)
  18. # Merge df_b into df_mri for the column "Group" based on "SubjectID" (assuming "SubjectID" is the column name in df_mri)
  19. merged_df = pd.merge(df_mri, df_b[['StudyID', 'Group']], left_on='SubjectID', right_on='StudyID', how='outer')
  20. # Specify the output path for the merged dataframe
  21. out_path = os.path.join(parent_dir, "output", "MRI")
  22. output_file_path = os.path.join(out_path, "MRI_files_with_group_distinction.csv")
  23. # Save merged_df to CSV
  24. merged_df.to_csv(output_file_path, index=False)
  25. # Now you have merged_df containing the merged dataframe with both MRI and behavior data
  26. # You can continue your analysis or processing with merged_df