I can't solve this simple problem and I'm asking for help here... I have DataFrame as follows and I want to select the first two rows in each group of 'a'
df = pd.DataFrame({'a':pd.Series(['NewYork','NewYork','NewYork','Washington','Washington','Texas','Texas','Texas','Texas']), 'b': np.arange(9)})
df
Out[152]:
a b
0 NewYork 0
1 NewYork 1
2 NewYork 2
3 Washington 3
4 Washington 4
5 Texas 5
6 Texas 6
7 Texas 7
8 Texas 8
that is, I want an output as follows:
a b
0 NewYork 0
1 NewYork 1
2 Washington 3
3 Washington 4
4 Texas 5
5 Texas 6
Thanks a lot for the help.