I have a pandas DataFrame like following.
df = pd.DataFrame([[1.1, 1.1, 1.1, 2.6, 2.5, 3.4,2.6,2.6,3.4,3.4,2.6,1.1,1.1,3.3], list(\'AAABBBBABCBDDD\'), [1.1,
If you use apply on the groupby, the function you pass is called on each group, passed as a DataFrame. So you can do:
df.groupby('ID').apply(lambda t: t.iloc[1])
However, this will raise an error if the group doesn't have at least two rows. If you want to exclude groups with fewer than two rows, that could be trickier. I'm not aware of a way to exclude the result of apply only for certain groups. You could try filtering the group list first by removing small groups, or return a one-row nan-filled DataFrame and do dropna on the result.