12345678910111213141516171819202122232425 |
- 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)
- # Define the input file path
- input_file_path = os.path.join(parent_dir, 'output', "Correlation_with_behavior", 'correlation_dti_with_behavior.csv')
- # Read the CSV file
- df = pd.read_csv(input_file_path)
- # Filter the DataFrame to get the highest absolute correlation coefficient for each combination
- correlation_results_shortened_df = df.loc[df.groupby(['Group', 'merged_timepoint', 'Qtype', 'mask_name', 'Behavior_test'])['R'].apply(lambda x: x.abs().idxmax())]
- # Define the output file path for the shortened DataFrame
- output_file_path_shortened = os.path.join(parent_dir, 'output', "Correlation_with_behavior", 'correlation_dti_with_behavior_shortened.csv')
- # Save the shortened correlation results DataFrame to a CSV file
- correlation_results_shortened_df.to_csv(output_file_path_shortened, index=False)
- print("Shortened correlation results saved successfully to 'correlation_dti_with_behavior_shortened.csv' in the output folder.")
|