Skip to content

Commit b779f43

Browse files
ggold7046im-vinicius
authored and
im-vinicius
committed
DOC add example of DataFrame.index (pandas-dev#52835)
1 parent 658ea54 commit b779f43

File tree

2 files changed

+44
-2
lines changed

2 files changed

+44
-2
lines changed

ci/code_checks.sh

-1
Original file line numberDiff line numberDiff line change
@@ -532,7 +532,6 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then
532532
pandas.api.extensions.ExtensionArray.ndim \
533533
pandas.api.extensions.ExtensionArray.shape \
534534
pandas.api.extensions.ExtensionArray.tolist \
535-
pandas.DataFrame.index \
536535
pandas.DataFrame.columns \
537536
pandas.DataFrame.__iter__ \
538537
pandas.DataFrame.keys \

pandas/core/frame.py

+44-1
Original file line numberDiff line numberDiff line change
@@ -11770,7 +11770,50 @@ def isin(self, values: Series | DataFrame | Sequence | Mapping) -> DataFrame:
1177011770
_info_axis_name: Literal["columns"] = "columns"
1177111771

1177211772
index = properties.AxisProperty(
11773-
axis=1, doc="The index (row labels) of the DataFrame."
11773+
axis=1,
11774+
doc="""
11775+
The index (row labels) of the DataFrame.
11776+
11777+
The index of a DataFrame is a series of labels that identify each row.
11778+
The labels can be integers, strings, or any other hashable type. The index
11779+
is used for label-based access and alignment, and can be accessed or
11780+
modified using this attribute.
11781+
11782+
Returns
11783+
-------
11784+
pandas.Index
11785+
The index labels of the DataFrame.
11786+
11787+
See Also
11788+
--------
11789+
DataFrame.columns : The column labels of the DataFrame.
11790+
DataFrame.to_numpy : Convert the DataFrame to a NumPy array.
11791+
11792+
Examples
11793+
--------
11794+
>>> df = pd.DataFrame({'Name': ['Alice', 'Bob', 'Aritra'],
11795+
... 'Age': [25, 30, 35],
11796+
... 'Location': ['Seattle', 'New York', 'Kona']},
11797+
... index=([10, 20, 30]))
11798+
>>> df.index
11799+
Index([10, 20, 30], dtype='int64')
11800+
11801+
In this example, we create a DataFrame with 3 rows and 3 columns,
11802+
including Name, Age, and Location information. We set the index labels to
11803+
be the integers 10, 20, and 30. We then access the `index` attribute of the
11804+
DataFrame, which returns an `Index` object containing the index labels.
11805+
11806+
>>> df.index = [100, 200, 300]
11807+
>>> df
11808+
Name Age Location
11809+
100 Alice 25 Seattle
11810+
200 Bob 30 New York
11811+
300 Aritra 35 Kona
11812+
11813+
In this example, we modify the index labels of the DataFrame by assigning
11814+
a new list of labels to the `index` attribute. The DataFrame is then
11815+
updated with the new labels, and the output shows the modified DataFrame.
11816+
""",
1177411817
)
1177511818
columns = properties.AxisProperty(axis=0, doc="The column labels of the DataFrame.")
1177611819

0 commit comments

Comments
 (0)