Skip to content

docs: add code samples for index and column properties #212

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 2 commits into from
Nov 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
79 changes: 78 additions & 1 deletion third_party/bigframes_vendored/pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -3106,14 +3106,91 @@ def index(self):
index is used for label-based access and alignment, and can be accessed
or modified using this attribute.

**Examples:**

>>> import bigframes.pandas as bpd
>>> bpd.options.display.progress_bar = None

You can access the index of a DataFrame via ``index`` property.

>>> df = bpd.DataFrame({'Name': ['Alice', 'Bob', 'Aritra'],
... 'Age': [25, 30, 35],
... 'Location': ['Seattle', 'New York', 'Kona']},
... index=([10, 20, 30]))
>>> df
Name Age Location
10 Alice 25 Seattle
20 Bob 30 New York
30 Aritra 35 Kona
<BLANKLINE>
[3 rows x 3 columns]
>>> df.index # doctest: +ELLIPSIS
<bigframes.core.indexes.index.Index object at ...>
>>> df.index.values
array([10, 20, 30], dtype=object)

Let's try setting a new index for the dataframe and see that reflect via
``index`` property.

>>> df1 = df.set_index(["Name", "Location"])
>>> df1
Age
Name Location
Alice Seattle 25
Bob New York 30
Aritra Kona 35
<BLANKLINE>
[3 rows x 1 columns]
>>> df1.index # doctest: +ELLIPSIS
<bigframes.core.indexes.index.Index object at ...>
>>> df1.index.values
array([('Alice', 'Seattle'), ('Bob', 'New York'), ('Aritra', 'Kona')],
dtype=object)

Returns:
The index labels of the DataFrame.
"""
raise NotImplementedError(constants.ABSTRACT_METHOD_ERROR_MESSAGE)

@property
def columns(self):
"The column labels of the DataFrame."
"""The column labels of the DataFrame.

**Examples:**

>>> import bigframes.pandas as bpd
>>> bpd.options.display.progress_bar = None

You can access the column labels of a DataFrame via ``columns`` property.

>>> df = bpd.DataFrame({'Name': ['Alice', 'Bob', 'Aritra'],
... 'Age': [25, 30, 35],
... 'Location': ['Seattle', 'New York', 'Kona']},
... index=([10, 20, 30]))
>>> df
Name Age Location
10 Alice 25 Seattle
20 Bob 30 New York
30 Aritra 35 Kona
<BLANKLINE>
[3 rows x 3 columns]
>>> df.columns
Index(['Name', 'Age', 'Location'], dtype='object')

You can also set new labels for columns.

>>> df.columns = ["NewName", "NewAge", "NewLocation"]
>>> df
NewName NewAge NewLocation
10 Alice 25 Seattle
20 Bob 30 New York
30 Aritra 35 Kona
<BLANKLINE>
[3 rows x 3 columns]
>>> df.columns
Index(['NewName', 'NewAge', 'NewLocation'], dtype='object')

"""
raise NotImplementedError(constants.ABSTRACT_METHOD_ERROR_MESSAGE)

def value_counts(
Expand Down
49 changes: 48 additions & 1 deletion third_party/bigframes_vendored/pandas/core/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,54 @@ def struct(self):

@property
def index(self):
"""The index (axis labels) of the Series."""
"""The index (axis labels) of the Series.

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.

**Examples:**

>>> import bigframes.pandas as bpd
>>> bpd.options.display.progress_bar = None

You can access the index of a Series via ``index`` property.

>>> df = bpd.DataFrame({'Name': ['Alice', 'Bob', 'Aritra'],
... 'Age': [25, 30, 35],
... 'Location': ['Seattle', 'New York', 'Kona']},
... index=([10, 20, 30]))
>>> s = df["Age"]
>>> s
10 25
20 30
30 35
Name: Age, dtype: Int64
>>> s.index # doctest: +ELLIPSIS
<bigframes.core.indexes.index.Index object at ...>
>>> s.index.values
array([10, 20, 30], dtype=object)

Let's try setting a multi-index case reflect via ``index`` property.

>>> df1 = df.set_index(["Name", "Location"])
>>> s1 = df1["Age"]
>>> s1
Name Location
Alice Seattle 25
Bob New York 30
Aritra Kona 35
Name: Age, dtype: Int64
>>> s1.index # doctest: +ELLIPSIS
<bigframes.core.indexes.index.Index object at ...>
>>> s1.index.values
array([('Alice', 'Seattle'), ('Bob', 'New York'), ('Aritra', 'Kona')],
dtype=object)

Returns:
The index labels of the Series.
"""
raise NotImplementedError(constants.ABSTRACT_METHOD_ERROR_MESSAGE)

@property
Expand Down