incooparate_behavior_data.py 1.5 KB

1234567891011121314151617181920212223242526272829303132333435
  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_drag', 'hindlimb_drop', 'foot_faults','paw_dragZ-score', 'hindlimb_dropZ-score', 'foot_faultsZ-score',
  20. 'averageScore', '2 Cluster', '3 Cluster', '4 Cluster', '5 Cluster', '6 Cluster']],
  21. on=['subjectID', 'merged_timepoint'], how='left')
  22. # Define the output file path
  23. output_file_path = os.path.join(parent_dir, 'output', 'Final_Quantitative_output','Quantitative_results_from_dwi_processing_merged_with_behavior_data.csv')
  24. # Save the merged DataFrame as a CSV file
  25. merged_df.to_csv(output_file_path, index=False)