my question is to make a sample for a grouped dataframe in pandas. I just grouped a dataset using pd.groupby, and the grouped dataset is like this, each bikeid has several trips:
bikeid tripid A B C
0 1 a1 b1 c1
2 a2 b2 c2
3 a3 b3 c3
1 4 a4 b4 c4
5 a5 b5 c5
2 6 ..............
7 ..............
3 8 ..............
9 ..............
What I want to do is just build a sample pick up one bikeid from every 3 bikeids. Should be like:
bikeid tripid A B C
0 1 a1 b1 c1
2 a2 b2 c2
3 a3 b3 c3
3 8 a8 b8 c8
9 a9 b9 c9
6 ..............
..............
9
...
However I tried to use grouped_new = grouped.sample(frac=0.3)
it comes out a sample based on each single trip but not base on bikeid.
Can anyone help me out with this? Thank you so much!!!