Skip to content

Commit fe098c0

Browse files
committed
trying to format documentation correctly
1 parent 83385d1 commit fe098c0

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

pandas/core/series.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1815,14 +1815,31 @@ def _set_name(
18151815
Parrot 30.0
18161816
Parrot 20.0
18171817
Name: Max Speed, dtype: float64
1818+
1819+
We can pass a list of values (Here: ["a", "b", "a", "b"]) to
1820+
group the Series data by custom labels:
1821+
18181822
>>> ser.groupby(["a", "b", "a", "b"]).mean()
18191823
a 210.0
18201824
b 185.0
18211825
Name: Max Speed, dtype: float64
1826+
1827+
Grouping by numeric labels yields similar results (Here: [0, 1, 0, 1]):
1828+
1829+
>>> ser.groupby([0, 1, 0, 1]).mean()
1830+
0 210.0
1831+
1 185.0
1832+
Name: Max Speed, dtype: float64
1833+
1834+
We can group by a level of the index:
1835+
18221836
>>> ser.groupby(level=0).mean()
18231837
Falcon 370.0
18241838
Parrot 25.0
18251839
Name: Max Speed, dtype: float64
1840+
1841+
We can group by a condition applied to the Series values:
1842+
18261843
>>> ser.groupby(ser > 100).mean()
18271844
Max Speed
18281845
False 25.0
@@ -1845,11 +1862,16 @@ def _set_name(
18451862
Parrot Captive 30.0
18461863
Wild 20.0
18471864
Name: Max Speed, dtype: float64
1865+
18481866
>>> ser.groupby(level=0).mean()
18491867
Animal
18501868
Falcon 370.0
18511869
Parrot 25.0
18521870
Name: Max Speed, dtype: float64
1871+
1872+
We can also group by the 'Type' level of the hierarchical index
1873+
to get the mean speed for each type:
1874+
18531875
>>> ser.groupby(level="Type").mean()
18541876
Type
18551877
Captive 210.0
@@ -1865,12 +1887,17 @@ def _set_name(
18651887
b 3
18661888
dtype: int64
18671889
1890+
To include `NA` values in the group keys, set `dropna=False`:
1891+
18681892
>>> ser.groupby(level=0, dropna=False).sum()
18691893
a 3
18701894
b 3
18711895
NaN 3
18721896
dtype: int64
18731897
1898+
We can also group by a custom list with NaN values to handle
1899+
missing group labels (Here: ["a", "b", "a", np.nan]):
1900+
18741901
>>> arrays = ['Falcon', 'Falcon', 'Parrot', 'Parrot']
18751902
>>> ser = pd.Series([390., 350., 30., 20.], index=arrays, name="Max Speed")
18761903
>>> ser.groupby(["a", "b", "a", np.nan]).mean()

0 commit comments

Comments
 (0)