Skip to content

Commit aa4a039

Browse files
ggold7046pmeier
andauthored
DOC add example of Series.index (#51842)
Co-authored-by: Philip Meier <[email protected]>
1 parent 75a79e7 commit aa4a039

File tree

2 files changed

+40
-2
lines changed

2 files changed

+40
-2
lines changed

ci/code_checks.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then
8585

8686
MSG='Partially validate docstrings (EX01)' ; echo $MSG
8787
$BASE_DIR/scripts/validate_docstrings.py --format=actions --errors=EX01 --ignore_functions \
88-
pandas.Series.index \
8988
pandas.Series.__iter__ \
9089
pandas.Series.keys \
9190
pandas.Series.item \

pandas/core/series.py

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5486,7 +5486,46 @@ def to_period(self, freq: str | None = None, copy: bool | None = None) -> Series
54865486
_info_axis_name: Literal["index"] = "index"
54875487

54885488
index = properties.AxisProperty(
5489-
axis=0, doc="The index (axis labels) of the Series."
5489+
axis=0,
5490+
doc="""
5491+
The index (axis labels) of the Series.
5492+
5493+
The index of a Series is used to label and identify each element of the
5494+
underlying data. The index can be thought of as an immutable ordered set
5495+
(technically a multi-set, as it may contain duplicate labels), and is
5496+
used to index and align data in pandas.
5497+
5498+
Returns
5499+
-------
5500+
Index
5501+
The index labels of the Series.
5502+
5503+
See Also
5504+
--------
5505+
Series.reindex : Conform Series to new index.
5506+
Series.set_index : Set Series as DataFrame index.
5507+
Index : The base pandas index type.
5508+
5509+
Notes
5510+
-----
5511+
For more information on pandas indexing, see the `indexing user guide
5512+
<https://pandas.pydata.org/docs/user_guide/indexing.html>`__.
5513+
5514+
Examples
5515+
--------
5516+
To create a Series with a custom index and view the index labels:
5517+
5518+
>>> cities = ['Kolkata', 'Chicago', 'Toronto', 'Lisbon']
5519+
>>> populations = [14.85, 2.71, 2.93, 0.51]
5520+
>>> city_series = pd.Series(populations, index=cities)
5521+
>>> city_series.index
5522+
Index(['Kolkata', 'Chicago', 'Toronto', 'Lisbon'], dtype='object')
5523+
5524+
To change the index labels of an existing Series:
5525+
>>> city_series.index = ['KOL', 'CHI', 'TOR', 'LIS']
5526+
>>> city_series.index
5527+
Index(['KOL', 'CHI', 'TOR', 'LIS'], dtype='object')
5528+
""",
54905529
)
54915530

54925531
# ----------------------------------------------------------------------

0 commit comments

Comments
 (0)