123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- # -*- coding: utf-8 -*-
- """
- Created on Mon May 11 16:55:37 2020
- @author: Cecilia
- """
- """
- Summerize the behavioral data (the table in TWF manuscript) and
- """
- import os
- import pandas as pd
- import numpy as np
- #%%
- ## Get the path of the folder where the data csv file sits in.
- ## The results will save to this folder.
- #csv_path = r"C:\Users\Cecilia\OneDrive\Python\TWF_behaviour\behaviouralRecalculated\TWF_ITD_dataset_withoutCorrectionTrials.csv"
- csv_path = r"C:\Users\USER\OneDrive\Python\TWF_behaviour\behaviouralRecalculated\TWF_ITD_dataset_withoutCorrectionTrials.csv"
- folder_path, csv_filename = os.path.split(csv_path)
- ## Load data file (without correction trials)
- dataset = pd.read_csv(csv_path,encoding='utf-8-sig', sep='\s*,\s*', engine='python').copy()
- ## Get rid of the white spaces in front or at the end of collumns. If not doing so, will raise error when calling get_group()
- dataset['animal'] = dataset['animal'].astype(str).str.strip()
- dataset.columns = dataset.columns.str.strip()
- ## Get the unique condition and animal ID
- conditions = list(dataset['condition'].unique())
- animals = list(dataset['animal'].unique())
- #%% How many probe trials in each condition for each rat
- ## Extract the offset (ms) == 0 (probe) trials
- probe_data = dataset.loc[dataset['offset (ms)'] == 0].copy()
- ## Group data by condition and animal
- grouped_probe_data = probe_data.groupby(['condition','animal'])
- ## Print out the number of trials in each conditon
- for (probe_condition, probe_animal), probe_group in grouped_probe_data:
- print("The total number of probe trials in group {} {} is {}".format(probe_condition, probe_animal, probe_group.shape[0] ))
-
- #%% How is the performance in honesty trial in each condition for each rat
- ## calculate the honesty trial correct rate in each condition
- honesty_data = dataset.loc[np.abs(dataset['offset (ms)'])>dataset['jitter (ms)']].copy()
- ## Group data by condition and animal
- grouped_honesty_data = honesty_data.groupby(['condition','animal'])
- for (honesty_condition, honesty_animal), honesty_group in grouped_honesty_data:
- # The number of correct trials in each group
- honesty_correct=sum(honesty_group['correct'])
- print('Honesty trials in group {} {} :- Total:{} Correct: {} ({}%)'.format(honesty_condition, honesty_animal, len(honesty_group),honesty_correct,honesty_correct*100/len(honesty_group)))
|