Assume groups will have more than n
memebers, I want to take every n
th row from each group. I looked at https://pandas.pydata.org/pandas-docs/version/0.17.0/generated/pandas.core.groupby.GroupBy.nth.html but that only takes one row from each group.
For example:
import pandas as pd
x = pd.DataFrame.from_dict({'a': [1, 1, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3], 'b': [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]})
a b
0 1 1
1 1 2
2 2 3
3 2 4
4 2 5
5 3 6
6 3 7
7 3 8
8 3 9
9 3 10
10 3 11
11 3 12
And if we are keeping every 2nd row:
a b
1 1 2
3 2 4
6 3 7
8 3 9
10 3 11