incooparate_behavior_data.py 1.3 KB

12345678910111213141516171819202122232425262728293031323334
  1. # -*- coding: utf-8 -*-
  2. """
  3. Created on Mon Apr 8 13:23:12 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_quant = os.path.join(parent_dir, 'output',"Final_Quantitative_output" ,'Quantitative_results_from_dwi_processing.csv')
  14. df_q = pd.read_csv(input_file_quant)
  15. # Read the behavior data CSV file into a Pandas DataFrame
  16. input_file_behav = os.path.join(parent_dir, 'output',"behavior_analysis" ,'behavior_data_processed.csv')
  17. df_b = pd.read_csv(input_file_behav)
  18. # Merge the columns from df_b into df_q based on subjectID and merged_timepoint columns
  19. merged_df = pd.merge(df_q, df_b[['subjectID', 'merged_timepoint', 'paw_dragZ-score', 'hindlimb_dropZ-score', 'foot_faultsZ-score', 'averageScore', '2 Cluster', '3 Cluster', '4 Cluster', '5 Cluster', '6 Cluster']],
  20. on=['subjectID', 'merged_timepoint'], how='left')
  21. # Define the output file path
  22. output_file_path = os.path.join(parent_dir, 'output', 'Final_Quantitative_output&behavior_data.csv')
  23. # Save the merged DataFrame as a CSV file
  24. merged_df.to_csv(output_file_path, index=False)