Untitled

mail@pastecode.io avatar
unknown
plain_text
8 months ago
1.9 kB
2
Indexable
Never
import os
import pandas as pd

# List of participants and types
participants = ["dkatalinic"]  # Add more participants as needed
types = ["standard", "slices", "snail"]  # Add more types as needed

# Dictionaries to store results
average_wpm_map = {}
average_ter_map = {}

# Iterate through participants and types
for participant in participants:
    for file_type in types:
        # Construct the file name
        file_name = f"{participant}_{file_type}.csv"
        
        # Check if the file exists
        if os.path.isfile(file_name):
            # Load the CSV file into a DataFrame
            data_frame = pd.read_csv(file_name)
            
            # Extract the 'WPM' column
            wpm_values = data_frame[' WPM'].tolist()
            
            # Calculate the average WPM
            average_wpm = sum(wpm_values) / len(wpm_values)
            
            # Extract the 'TER' column
            ter_values = data_frame[' TER'].tolist()
            
            # Calculate the average TER
            average_ter = sum(ter_values) / len(ter_values)
            
            # Create the key for the dictionaries
            key = f"{participant}_{file_type}"
            
            # Save the results to the dictionaries
            average_wpm_map[key] = average_wpm
            average_ter_map[key] = average_ter

df = pd.DataFrame({
    'Type': [file_type for participant in participants for file_type in types],
    'Average TER': [average_ter_map[f"{participant}_{file_type}"] for participant in participants for file_type in types],
    'Average WPM': [average_wpm_map[f"{participant}_{file_type}"] for participant in participants for file_type in types]
})

# Save the DataFrame to an Excel file without the MultiIndex
excel_file_path = "average_results.xlsx"
df.to_excel(excel_file_path, index=False)

print(f"Excel file saved at: {excel_file_path}")
Leave a Comment