I am trying to create a new variable (column) in an existing dataframe.
Participant Session Trial_number Accuracy Block
G01S01 1 3 1 1
G01S02 1 4 1 2
G02S01 1 5 1 5
G01S01 1 6 1 8
G01S01 1 7 1 10
Basically, I want to create a new variable "Epoch" based on the Block column. Block values between 1-4 belong to Epoch 1, Epoch 2 the other four and so on. It would look something like this:
Participant Session Trial_number Accuracy Block Epoch
G01S01 1 3 1 1 1
G01S02 1 4 1 2 1
G02S01 1 5 1 5 2
G01S01 1 6 1 8 2
G01S01 1 7 1 10 3
Additionally, I also want to create another variable based on the Participant ID, if it ends with 1 the participant belongs to group 1, if it ends with 2, the participant belongs to group 2.
I tried doing the first problem, but basically did not work.
import pandas as pd
df = pd.read_csv('merge.csv')
Epoch = []
x = 0
while x < 179424:
if df['Block'][x] < 5:
Epoch == 1
elif 4 < df['Block'][x] < 9:
Epoch == 2
elif 8 < df['Block'][x] < 13:
Epoch == 3
elif 12 < df['Block'][x] < 17:
Epoch == 4
else:
Epoch == 5
x += 1
(179424 is the number of rows in my spreadsheet)