Pandas has an inconsistent behavior when doing a groupby-apply with one group :
(
pd.DataFrame({'c1': [0, 0, 0],
'c2': [1, 2, 3]})
.groupby('c1')
.apply(lambda df: df['c2']).shape
)
is equal to (1, 3)
while
(
pd.DataFrame({'c1': [0, 0, 1],
'c2': [1, 2, 3]})
.groupby('c1')
.apply(lambda df: df['c2']).shape
)
is equal to (3, ).
When there only one unique value in the groupby variable, the resulting Serie is transposed from what I expect.
I need a consistent behavior : the number of rows must be kept at 3 no matter the number of groups.