I'd like to have your help on the following issue:
I have run two psychology experiments and I have retrieved reaction times from my subjects. All of this data is submitted to various .xlsx files in dataframes (one file per experiment) and with Python I created a single .xlsx file that contains all of them (through .append) The index of my master file is the subject ID which starts from 1.
The problem that I have now is that I have 12 subjects, and Python does not seem to follow the natural sorting rules...What I have is that subject 10, 11, 12 come before subject 1 - 9 (which messes up the way I retrieve my data). I have used natsort in such a way:
MASTER_DF_FLAT.index = natsorted(MASTER_DF_FLAT.index)
MASTER_DF_FV.index = natsorted(MASTER_DF_FV.index)
This fixes the problem with the indexes, but the data on the rows won't follow the new order (on excel you can "extend the selection" and you get away with it). Any idea how I can fix this?
EDIT: here is how the data is formatted with 10+ subjects:
subject block trial condition RT
10 1 1 1 0,677044666
10 1 2 12 0,556960872
10 1 3 2 0,51685685
10 1 4 5 0,766190078
And here is the data from subject 1:
subject block trial condition RT
1 1 1 1 0,677044666
1 1 2 12 0,556960872
1 1 3 2 0,51685685
1 1 4 5 0,766190078
As you can see the RTs have not changed (and so did not the other values)
Thanks for your help!
EDIT1: here is how i save my files:
I do that :) Here is my code exactly:
for f in files:
data = os.path.join(data_dir,f)
df = pd.read_excel(data)
df.set_index('subject', inplace = True)
concatenated = pd.concat([block, trial, condition, RT, SOA, acc, ISI], axis=1)
if 'FV' not in f:
flatDFs.append(concatenated)
else:
fvDFs.append(concatenated)
MASTER_DF_FLAT = pd.concat(flatDFs)
writerFlat = pd.ExcelWriter('MASTER_FILE_FLAT.xlsx')
MASTER_DF_FLAT.to_excel(writerFlat,'Sheet1')
writerFlat.save()
As you can see, the index in my .xlsx file is indeed subject. Everything works fine, it's just the order of elements!