SeriesGroupBy.apply results in wrong name when there is a single group · Issue #46369 · pandas-dev/pandas (original) (raw)
df = pd.DataFrame({'a': [0], 'b': [1]})
ser = df['b'].rename(None)
print(ser.groupby(df['a']).apply(lambda x: x))
df = pd.DataFrame({'a': [0, 1], 'b': [1, 2]})
ser = df['b'].rename(None)
print(ser.groupby(df['a']).apply(lambda x: x))
produces
0 1
Name: 0, dtype: int64
0 1
1 2
dtype: int64
In the first case, the name
attribute on the resulting Series is set as 0
, the group. In the second case, the two groups have different names and so the correct name
attribute of None
is on the result. The name
attribute should be None
in the first case as well.