12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- # -*- coding: utf-8 -*-
- """
- Created on Mon Mar 18 22:12:25 2024
- @author: arefk
- """
- import pandas as pd
- import os
- # 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)
- # 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_data = os.path.join(parent_dir, 'output',
- "Final_Quantitative_output",
- 'Quantitative_results_from_dwi_processing.csv')
- # Read the CSV file
- df0 = pd.read_csv(input_file_path_data)
- #filter anything?
- df = df0[(df0["Qtype"] == "rd") &
- (df0["mask_name"] == "CC_MOp(dilated)_cut.tt") &
- (df0["dialation_amount"] == 0)]
- Values = ["Value"]
- #%%
- # Create an empty DataFrame to store the transposed data
- transposed_data = pd.DataFrame()
- transpodeCloulmn = "Group"
- for vv in Values:
- # Create an empty DataFrame to store the transposed data for this value
- value_transposed_data = pd.DataFrame()
- for group_value in df[transpodeCloulmn].unique():
- # Filter DataFrame for current group value
- filtered_df = df[df[transpodeCloulmn] == group_value]
- # Pivot the DataFrame for current value and group
- pivot_df = pd.pivot_table(filtered_df, values=vv, index="merged_timepoint", columns=["subjectID", transpodeCloulmn])
- # Concatenate pivot_df to value_transposed_data
- value_transposed_data = pd.concat([value_transposed_data, pivot_df], axis=1)
- # Rename the index in value_transposed_data
- value_transposed_data.index.name = vv
- # Concatenate value_transposed_data with transposed_data along the first dimension
- transposed_data = pd.concat([transposed_data, value_transposed_data, pd.DataFrame(index=[vv])])
- # Define the output file path
- output_file_path = os.path.join(parent_dir, 'output', "Final_Quantitative_output",'Transposed4Prism_FA_CC_MOP_dialated.csv')
- transposed_data.to_csv(output_file_path, index=True, header=True)
- print("Data restructured and saved successfully.")
|