Help needed with exporting data to one excel spreadsheet

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 :frowning:

Also half the files are.log or .psydat instead of .csv, and im not sure if this affects anything?

Hi. I’ve made this the subject of today’s tip.

The .log and .psydat files will be ignored during the merge.

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?

Open the Python file in Coder and press run.

If PsychoPy is crashing, please show the error message.

there isn’t any error message, it’s just frozen on me and i cant exit out of it either

Nevermind, i have got it to work again, so do i just simply copy and paste the whole code? including the part where is says chatgpt at the top?

Also, i am on a macbook :slight_smile: just in case that changes anything?

Yes to copying the whole code.

I don’t know what happens when you open a dialogue box on a Mac (to find the data folder). Have you managed to run the code yet?

i tried, it came up with this:

Traceback (most recent call last):
File “”, line 1, in
ModuleNotFoundError: No module named ‘tkinter’
Traceback (most recent call last):
File “”, line 1, in
ModuleNotFoundError: No module named ‘tkinter’
… … … … … … … … … … … … … … … … … … … … … … … … … … … … … … … … … … … … … >>> >>> >>> …

Option 1:

Try to install tkinter by running pip install tk in a PIP terminal in Plugins and Packages (from the Tools menu)

Option 2:

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)

Note I have used / not \

1 Like

Hello @ellawright101

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.

Best wishes Jens