79718447

Date: 2025-07-29 10:22:00
Score: 0.5
Natty:
Report link

Perhaps you meant to do this?

reset_sf = sf.reset_index(drop=True)
grouped = **reset_sf**.groupby(reset_sf)
# outputs
# Group: 10
# 0    10
# 1    10
# dtype: int64
# Group: 20
# 2    20
# dtype: int64
# Group: 30
# 3    30
# 4    30
# 5    30
# dtype: int64

since

sf.reset_index(drop=True)
# outputs
# 0    10
# 1    10
# 2    20
# 3    30
# 4    30
# 5    30
#dtype: int64

but

sf = pd.Series([10, 10, 20, 30, 30, 30], index=np.arange(6)+2)
# outputs
# 2    10
# 3    10
# 4    20
# 5    30
# 6    30
# 7    30
# dtype: int64

have different indexes, which give different results from groupby so groupby works for index 2,3...5 or values 20,30 only

grouped = sf.groupby(sf.reset_index(drop=True))
# outputs
# Group: 20.0
# 2    10
# dtype: int64
# Group: 30.0
# 3    10
# 4    20
# 5    30

(though I don't know why index 3,4 is values 10,20)

Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Contains question mark (0.5):
  • Low reputation (1):
Posted by: deV8nnek