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