Suppose I have the following dataset:
uid iid val
1 1 2
1 2 3
1 3 4
1 4 4.5
1 5 5.5
2 1 3
2 2 3
2 3 4
3 4 4.5
3 5 5.5
From this data, I want to first groupby uid, then get last 20% of number of rows from each uid.
That is, since uid=1 has 5 rows, I want to obtain last 1 row (20% of 5) from uid=1.
The following is what I want to do:
df.groupby('uid').tail([20% of each uid])
Can anyone help me?