Skip to content

DOC add example of Series.index #51842

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 27 commits into from
Apr 16, 2023
Merged
Changes from 24 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 42 additions & 1 deletion pandas/core/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -5745,7 +5745,48 @@ def to_period(self, freq: str | None = None, copy: bool | None = None) -> Series
_info_axis_name: Literal["index"] = "index"

index = properties.AxisProperty(
axis=0, doc="The index (axis labels) of the Series."
axis=0,
doc="""
The index (axis labels) of the Series.

Get the index (row labels) of the Series.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure what this sentence adds - why not move the paragraph starting with

The index of a Series is used to label and identify each element of the

to here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to here?

I did not get it. Could you please tell me where to move ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

where I left the comment. i.e. instead of this "Get the index (row labels) of the Series." paragraph

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @MarcoGorelli , I tried to move that paragraph The index of a Series is used to label and identify each element of the to the first line replacing Get the index (row labels) of the Series., but it failed the CI. In the pandas documentation it is said that the first summary line should be a single meaning full line. And then an extending summary. So can we keep that single line as it is and can I revert back to the old commit ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure what you mean here @ggold7046. The summary, i.e.

The index (axis labels) of the Series.

is a single line. The CI fails because you again included trailing white space in the blank line.


Returns
-------
Index
The index labels of the Series.

See Also
--------
Series.reindex : Conform Series to new index.
Series.set_index : Set Series as DataFrame index.
Index : The base pandas index type.

Notes
-----
The index of a Series is used to label and identify each element of the
underlying data. The index can be thought of as an immutable ordered set
(technically a multi-set, as it may contain duplicate labels), and is
used to index and align data in pandas.

For more information on pandas indexing, see the `indexing user guide
<https://pandas.pydata.org/docs/user_guide/indexing.html>`__.

Examples
--------
To create a Series with a custom index and view the index labels:

>>> cities = ['Kolkata', 'Chicago', 'Toronto', 'Lisbon']
>>> populations = [14.85, 2.71, 2.93, 0.51]
>>> city_series = pd.Series(populations, index=cities)
>>> city_series.index
Index(['Kolkata', 'Chicago', 'Toronto', 'Lisbon'], dtype='object')

To change the index labels of an existing Series:
>>> city_series.index = ['KOL', 'CHI', 'TOR', 'LIS']
>>> city_series.index
Index(['KOL', 'CHI', 'TOR', 'LIS'], dtype='object')
""",
)

# ----------------------------------------------------------------------
Expand Down