-
-
Notifications
You must be signed in to change notification settings - Fork 18.6k
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
Changes from 1 commit
318c8da
8e0951a
112928f
5369605
aa00a24
d3692a5
bd823b5
4ab4d96
f3c576b
17da370
c5c8720
9c311ea
14bb848
ddb0fda
4d70353
156fca4
fc3c0ed
680a0a7
a1cf36d
62be40a
5c5dd5b
22da748
ec0335e
87fccff
c98e6e2
cb41a90
72c6ad2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5993,6 +5993,54 @@ def mask( | |
|
||
index = properties.AxisProperty( | ||
axis=0, doc="The index (axis labels) of the Series." | ||
""" | ||
|
||
A one-dimensional ndarray with hashable type axis labels. | ||
|
||
Pandas Series.index attribute is used to get or set the index labels of the given Series object. | ||
The object supports both integer- and label-based indexing and provides a host of methods for performing | ||
operations involving the index. | ||
The labels need not be unique but must be of the hashable type. | ||
|
||
Returns | ||
------- | ||
index | ||
|
||
Examples | ||
-------- | ||
|
||
**Use the Series.index attribute to set the index label for the given Series object.** | ||
|
||
>>> s = pd.Series(['Kolkata', 'Chicago', 'Toronto', 'Lisbon']) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This example is not very realistic and confusing with the Also, since here you're just showing the |
||
>>> print(s) | ||
0 Kolkata | ||
1 Chicago | ||
2 Toronto | ||
3 Lisbon | ||
dtype: object | ||
|
||
The ``Series.index`` attribute will now be used to set the index label for the given object. | ||
|
||
>>> s.index = ['City 1', 'City 2', 'City 3', 'City 4'] | ||
>>> print(s) | ||
City 1 Kolkata | ||
City 2 Chicago | ||
City 3 Toronto | ||
City 4 Lisbon | ||
dtype: object | ||
|
||
As we can see in the output, the ``Series.index`` attribute has successfully set the index labels for the given Series object. | ||
|
||
**We can also assign duplicate or nonunique indexes in Pandas.** | ||
|
||
>>> s.index = ['City 1', 'City 1', 'City 3', 'City 3'] | ||
>>> print(s) | ||
City 1 Kolkata | ||
City 1 Chicago | ||
City 3 Toronto | ||
City 3 Lisbon | ||
dtype: object | ||
""" | ||
ggold7046 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
) | ||
|
||
# ---------------------------------------------------------------------- | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you make this a single text, not concatenating in this way please?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, but didn't understand. You mean like this ?
axis=0, doc="The index (axis labels) of the Series." """ A one-dimensional ndarray with hashable type axis labels. """
or this
axis=0, doc="The index (axis labels) of the Series."
""" A one-dimensional ndarray with hashable type axis labels. """
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ggold7046
Could you please use triple backticks to format code blocks? Without it, your question is really hard to read.
What @datapythonista means is that you have two strings here that will be concatenated:
Since you already have a multiline string (triple quotes), you can just merge the two: