def f(group):
    row = group.irow(0)
return DataFrame({'class': [row['class']] * row['count']})
df.groupby('class', group_keys=False).apply(f)
pandas: apply function to DataFrame that can return multiple rows