Data Analysis: final df get an empty sequence

mail@pastecode.io avatar
unknown
python
a year ago
2.5 kB
4
Indexable
session_values = np.unique(dat_df['filename'])
soa_values = np.unique(dat_df['soa'])
final_df = pd.DataFrame({'soa': [], 'perf_congr': [], 'perf_incongr': [], 'RT_congr': [], 'RT_incongr':[], 'n_congr': [], 'n_incongr':[]})

for day in session_values:
    session = dat_df[dat_df['filename']==day]
    
    #filename_lst = []
    #soas_lst = []
    #congr_perf_lst = []
    #incongr_perf_lst = []
    #congr_n = []
    #incongr_n = []
    #congr_RT_lst = []
    #incongr_RT_lst = []
    for i in soa_values:

        filename_lst = []
        soas_lst = []
        congr_perf_lst = []
        incongr_perf_lst = []
        congr_n = []
        incongr_n = []
        congr_RT_lst = []
        incongr_RT_lst = []

        subset = session[session['soa'] == i]

        ## CONGRUENT
        corr_congr = subset[(subset['hit_from_eye'] == True) & (subset['cue_lum_congruency'] == "congruent")]
        incorr_congr = subset[(subset['hit_from_eye'] == False) & (subset['cue_lum_congruency'] == "congruent")]
        congr_n_trials = len(corr_congr) + len(incorr_congr)

        ## INCONGRUENT
        corr_incongr = subset[(subset['hit_from_eye'] == True) & (subset['cue_lum_congruency'] == "incongruent")]
        incorr_incongr = subset[(subset['hit_from_eye'] == False) & (subset['cue_lum_congruency'] == "incongruent")]
        incongr_n_trials = len(corr_incongr) + len(incorr_incongr)

        if congr_n_trials >= 1 and incongr_n_trials >= 1:
            soas_lst.append(i)
            congr_perf = len(corr_congr) / congr_n_trials
            #print(congr_n_trials)
            congr_n.append(congr_n_trials)
            congr_perf_lst.append(congr_perf)
            #print('Performance in congruent:', congr_perf, 'soa', i)
            congr_RT =  np.mean(corr_congr['saccade_time_to_lum'])
            congr_RT_lst.append(congr_RT)
            incongr_perf = len(corr_incongr) / incongr_n_trials
            incongr_n.append(incongr_n_trials)
            incongr_perf_lst.append(incongr_perf)
            #print('Performance in incongruent:', incongr_perf, 'soa', i)
            incongr_RT = np.mean(corr_incongr['saccade_time_to_lum'])
            incongr_RT_lst.append(incongr_RT)
            
        temp_df = pd.DataFrame({'soa': soas_lst, 'perf_congr': congr_perf_lst, 'perf_incongr': incongr_perf_lst, 
                'RT_congr': congr_RT_lst, 'RT_incongr': incongr_RT_lst, 'n_congr': congr_n, 'n_incongr':incongr_n})
        final_df = pd.concat([final_df,temp_df])
Leave a Comment