Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create hf_percent_correct_group #2

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions hf_percent_correct_group
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Tue Oct 22 12:12:02 2019

@author: katieemmons
"""

import pandas as pd
import glob

'''
to calculate average percent correct for an entire group (100, 200,...,500) us the script below
replace path with desired group folder
'''

#choose folder
path = r'/Users/katieemmons/Desktop/behavioral/100'

#searches for files in path that end in .txt
filenames = glob.glob(path + '/*.txt')

#creates df of all files in folder
df = pd.concat((pd.read_csv(f) for f in filenames))
df['correct resp'] = df.resp == df.want

#list of conditions to search for in percentCorrect(str)
conditions = ["maintain space", "maintain pitch", "maintain both", "switch space", "switch pitch", "switch both"]

#function to calculate average percent correct for a given condition
def percentCorrect(str):
correct_responses = (df.loc[df['cond'] == str, 'correct resp'].sum())
total_trials = ((df['cond'] == str).sum())
return (correct_responses/total_trials * 100)

#iterates percentCorrect over all conditions, prints result
for x in conditions:
percentCorrect(x)
print(x, percentCorrect(x))