Skip to content

Commit

Permalink
DOC add example of DataFrame.index (#52835)
Browse files Browse the repository at this point in the history
  • Loading branch information
ggold7046 committed Apr 23, 2023
1 parent e28d17b commit 7b710c7
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 2 deletions.
1 change: 0 additions & 1 deletion ci/code_checks.sh
Expand Up @@ -532,7 +532,6 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then
pandas.api.extensions.ExtensionArray.ndim \
pandas.api.extensions.ExtensionArray.shape \
pandas.api.extensions.ExtensionArray.tolist \
pandas.DataFrame.index \
pandas.DataFrame.columns \
pandas.DataFrame.__iter__ \
pandas.DataFrame.keys \
Expand Down
45 changes: 44 additions & 1 deletion pandas/core/frame.py
Expand Up @@ -11770,7 +11770,50 @@ def isin(self, values: Series | DataFrame | Sequence | Mapping) -> DataFrame:
_info_axis_name: Literal["columns"] = "columns"

index = properties.AxisProperty(
axis=1, doc="The index (row labels) of the DataFrame."
axis=1,
doc="""
The index (row labels) of the DataFrame.
The index of a DataFrame is a series of labels that identify each row.
The labels can be integers, strings, or any other hashable type. The index
is used for label-based access and alignment, and can be accessed or
modified using this attribute.
Returns
-------
pandas.Index
The index labels of the DataFrame.
See Also
--------
DataFrame.columns : The column labels of the DataFrame.
DataFrame.to_numpy : Convert the DataFrame to a NumPy array.
Examples
--------
>>> df = pd.DataFrame({'Name': ['Alice', 'Bob', 'Aritra'],
... 'Age': [25, 30, 35],
... 'Location': ['Seattle', 'New York', 'Kona']},
... index=([10, 20, 30]))
>>> df.index
Index([10, 20, 30], dtype='int64')
In this example, we create a DataFrame with 3 rows and 3 columns,
including Name, Age, and Location information. We set the index labels to
be the integers 10, 20, and 30. We then access the `index` attribute of the
DataFrame, which returns an `Index` object containing the index labels.
>>> df.index = [100, 200, 300]
>>> df
Name Age Location
100 Alice 25 Seattle
200 Bob 30 New York
300 Aritra 35 Kona
In this example, we modify the index labels of the DataFrame by assigning
a new list of labels to the `index` attribute. The DataFrame is then
updated with the new labels, and the output shows the modified DataFrame.
""",
)
columns = properties.AxisProperty(axis=0, doc="The column labels of the DataFrame.")

Expand Down

0 comments on commit 7b710c7

Please sign in to comment.