Hiya!
I have conducted my experiment and I now need to analyse my results. However, when i download my data files, it does not seem straight forward on how to successfully export these into a single excel sheet. I think i have been able to zip the file, and the file with all the data is now on my laptop files, but i keep running into issues when trying to move all this data into excel! Is there a way to get everyones data into one excel sheet? I am really struggling and im not techy at all so have no idea what to do
Also half the files are.log or .psydat instead of .csv, and im not sure if this affects anything?
I’m still really confused im sorry. How do i do this? PsychoPy keeps crashing on me and i dont understand code whatsoever. Is there any easier way to do this?
Use the following code instead where you specify the data folder in the code
# Created using ChatGPT
import os
import pandas as pd
def merge_csv_files(output_file,input_folder):
# List all CSV files in the input folder
csv_files = [f for f in os.listdir(input_folder) if f.endswith('.csv')]
if not csv_files:
print("No CSV files found in the selected folder.")
return
# Initialize an empty list to hold DataFrames
dfs = []
for file in csv_files:
# Construct full file path
file_path = os.path.join(input_folder, file)
# Read each CSV file into a DataFrame
df = pd.read_csv(file_path, encoding='windows-1256')
# Append the DataFrame to the list
dfs.append(df)
# Concatenate all DataFrames vertically (stacking them)
merged_df = pd.concat(dfs, ignore_index=True)
# Write the merged DataFrame to a new CSV file in folder above data folder
merged_df.to_csv(input_folder + "/../" + output_file, index=False, encoding='windows-1256')
print(f'Merged CSV saved as: {output_file}')
# Usage
output_file = 'merged_files.csv' # Set the output file name
input_folder = 'C:/Users/morys/Documents/Data/Emotional Stroop/data' # Set data folder
merge_csv_files(output_file,input_folder)
Excel offers the possibility of merging several csv files stored in a folder into one Excel-file. Go to the Data ribbon, select Get Data and then *From Folder, then select one of the three options offered.
If this is not enough information, a search for “how to read multiple csv in Excel” will return numerous descriptions.