grouped = s.groupby(s)

Or:

grouped = s.groupby(lambda x: s[x])
Answer from user1201614 on Stack Overflow
🌐
Pandas
pandas.pydata.org › docs › reference › api › pandas.Series.groupby.html
pandas.Series.groupby — pandas 3.0.3 documentation
An exception to this is that pandas ... user guide linked above for more details. ... >>> ser = pd.Series([390., 350., 30., 20.], ... index=['Falcon', 'Falcon', 'Parrot', 'Parrot'], ......
🌐
Pandas
pandas.pydata.org › pandas-docs › stable › reference › api › pandas.Series.groupby.html
pandas.Series.groupby — pandas 3.0.1 documentation
An exception to this is that pandas ... user guide linked above for more details. ... >>> ser = pd.Series([390., 350., 30., 20.], ... index=['Falcon', 'Falcon', 'Parrot', 'Parrot'], ......
🌐
w3resource
w3resource.com › pandas › series › series-groupby.php
Pandas: Series - groupby() function - w3resource
import numpy as np import pandas as pd df = pd.DataFrame({'Animal': ['Tiger', 'Tiger', 'Dog', 'Dog'], 'Max Speed': [270., 260., 36., 32.]}) df.groupby(['Animal']).mean() ... import numpy as np import pandas as pd arrays = [['Tiger', 'Tiger', 'Dog', 'Dog'], ['Captive', 'Wild', 'Captive', 'Wild']] index = pd.MultiIndex.from_arrays(arrays, names=('Animal', 'Type')) df = pd.DataFrame({'Max Speed': [280., 250., 30., 20.]}, index=index) df
🌐
pandas
pandas.pydata.org › pandas-docs › dev › reference › api › pandas.Series.groupby.html
pandas.Series.groupby — pandas ain documentation
An exception to this is that pandas ... linked above for more details. ... >>> ser = pd.Series( ... [390.0, 350.0, 30.0, 20.0], ... index=["Falcon", "Falcon", "Parrot", "Parrot"], ......
🌐
Spark By {Examples}
sparkbyexamples.com › home › pandas › how to groupby index in pandas?
How to GroupBy Index in Pandas? - Spark By {Examples}
July 3, 2025 - How to perform groupby index in pandas? Pass the index name of the DataFrame as a parameter to the groupby() function to group rows on an index.
🌐
Pandas
pandas.pydata.org › pandas-docs › version › 1.5 › reference › api › pandas.Series.groupby.html
pandas.Series.groupby — pandas 1.5.2 documentation
Returns a groupby object that contains information about the groups. ... Convenience method for frequency conversion and resampling of time series. ... See the user guide for more detailed usage and examples, including splitting an object into groups, iterating through groups, selecting a group, aggregation, and more. ... >>> ser = pd.Series([390., 350., 30., 20.], ... index=['Falcon', 'Falcon', 'Parrot', 'Parrot'], name="Max Speed") >>> ser Falcon 390.0 Falcon 350.0 Parrot 30.0 Parrot 20.0 Name: Max Speed, dtype: float64 >>> ser.groupby(["a", "b", "a", "b"]).mean() a 210.0 b 185.0 Name: Max Speed, dtype: float64 >>> ser.groupby(level=0).mean() Falcon 370.0 Parrot 25.0 Name: Max Speed, dtype: float64 >>> ser.groupby(ser > 100).mean() Max Speed False 25.0 True 370.0 Name: Max Speed, dtype: float64
🌐
Pandas
pandas.pydata.org › docs › reference › api › pandas.core.groupby.SeriesGroupBy.indices.html
pandas.core.groupby.SeriesGroupBy.indices — pandas 2.3.3 documentation
Examples · For SeriesGroupBy: >>> lst = ['a', 'a', 'b'] >>> ser = pd.Series([1, 2, 3], index=lst) >>> ser a 1 a 2 b 3 dtype: int64 >>> ser.groupby(level=0).indices {'a': array([0, 1]), 'b': array([2])} For DataFrameGroupBy: >>> data = [[1, 2, 3], [1, 5, 6], [7, 8, 9]] >>> df = pd.DataFrame(data, ...
Find elsewhere
🌐
Pandas
pandas.pydata.org › docs › reference › groupby.html
GroupBy — pandas 3.0.2 documentation - PyData |
pandas.api.typing.DataFrameGroupBy and pandas.api.typing.SeriesGroupBy instances are returned by groupby calls pandas.DataFrame.groupby() and pandas.Series.groupby() respectively · DataFrameGroupBy.__iter__()
🌐
Pandas
pandas.pydata.org › docs › reference › api › pandas.DataFrame.groupby.html
pandas.DataFrame.groupby — pandas 3.0.3 documentation
DataFrame.groupby(by=None, level=None, *, as_index=True, sort=True, group_keys=True, observed=True, dropna=True)[source]# Group DataFrame using a mapper or by a Series of columns.
🌐
Real Python
realpython.com › pandas-groupby
pandas GroupBy: Your Guide to Grouping Data in Python – Real Python
January 19, 2025 - Earlier you saw that the first parameter to .groupby() can accept several different arguments: ... You can take advantage of the last option in order to group by the day of the week. Use the index’s .day_name() to produce a pandas Index of strings.
🌐
Pandas
pandas.pydata.org › docs › user_guide › groupby.html
Group by: split-apply-combine — pandas 3.0.3 documentation
Another aggregation example is to compute the size of each group. This is included in GroupBy as the size method. It returns a Series whose index consists of the group names and the values are the sizes of each group.
🌐
Pandas
pandas.pydata.org › docs › reference › api › pandas.core.groupby.SeriesGroupBy.count.html
pandas.core.groupby.SeriesGroupBy.count — pandas 2.3.3 documentation
Apply a function groupby to each row or column of a DataFrame. Examples · For SeriesGroupBy: >>> lst = ['a', 'a', 'b'] >>> ser = pd.Series([1, 2, np.nan], index=lst) >>> ser a 1.0 a 2.0 b NaN dtype: float64 >>> ser.groupby(level=0).count() a 2 b 0 dtype: int64 ·
🌐
Statology
statology.org › home › pandas: how to group by index and perform calculation
Pandas: How to Group By Index and Perform Calculation
December 18, 2023 - #find count of unique values of 'points' grouped by 'position index column df.groupby(['team', 'points'])['rebounds'].nunique() team points A 7 1 16 1 19 1 B 8 2 9 1 10 1 Name: rebounds, dtype: int64 · The following tutorials explain how to perform other common operations in pandas:
🌐
Spark By {Examples}
sparkbyexamples.com › home › pandas › pandas series groupby() function with examples
Pandas Series groupby() Function with Examples - Spark By {Examples}
March 27, 2024 - The groupby() function in the Pandas Series is a powerful tool for grouping data based on certain criteria. The groupby operation is used to split a
🌐
Linux find Examples
queirozf.com › entries › pandas-dataframe-groupby-examples
Pandas DataFrame: GroupBy Examples
October 18, 2020 - import pandas as pd df = pd.DataFrame({ 'value':[20,22,32,111,33,100,99], 'product':['table','chair','chair','mobile phone','table','mobile phone','table'] }) # you can define a function like this or use a lambda function def count_even_numbers(series): return len([elem for elem in series if ...
🌐
Pandas
pandas.pydata.org › docs › dev › reference › api › pandas.Series.groupby.html
pandas.Series.groupby — pandas 3.0.0.dev0+2709.g415830fc8f documentation
An exception to this is that pandas ... user guide linked above for more details. ... >>> ser = pd.Series([390., 350., 30., 20.], ... index=['Falcon', 'Falcon', 'Parrot', 'Parrot'], ......
🌐
Built In
builtin.com › data-science › pandas-groupby
Pandas Groupby: 5 Methods to Know in Python | Built In
See last row of each group in Pandas groupby. | Image: Suraj Gurav · .first() and .last() returned the first and the last row once all the rows were grouped under each Product_Category. You can also extract a row at any other position, as well. For example, extracting the fourth row in each group is also possible using function .nth(). ... Remember, indexing in Python starts with zero, therefore, when you say .nth(3), you are actually accessing the fourth row.
🌐
GeeksforGeeks
geeksforgeeks.org › how-to-do-groupby-on-a-multiindex-in-pandas
How to do groupby on a multiindex in Pandas? - GeeksforGeeks
June 9, 2022 - In this article, we will be showing how to use the groupby on a Multiindex Dataframe in Pandas. In Data science when we are performing exploratory data analysis, we often use groupby to group the data of one column based on the other column. So, we are able to analyze how the data of one column is grouped or depending based upon the other column.