I am trying to iteratively create subsets of a dataframe. A toy example:
In:
A B participant
0 1 3 1
1 2 4 1
2 5 8 2
3 4 9 2
4 3 7 3
(The conditional statement thanks to the commenter below)
for p in df:
subset = df[df['participant'] == p].loc[: , 'A']
The desired outcome is:
A participant
0 1 1
1 2 1
A participant
0 5 2
1 4 2
etc.
But the for loop makes a subset by row, not by participant. How to get subsets per participant?
original attempt:
for p in df:
p.pressure = df[(:, 'pressure') & (df['participant'] == p)]