bigframes.pandas.Series.loc#

property Series.loc: LocSeriesIndexer#

Access a group of rows and columns by label(s) or a boolean array.

Examples:

>>> df = bpd.DataFrame([[1, 2], [4, 5], [7, 8]],
...                    index=['cobra', 'viper', 'sidewinder'],
...                    columns=['max_speed', 'shield'])
>>> df
            max_speed  shield
cobra               1       2
viper               4       5
sidewinder          7       8

[3 rows x 2 columns]

Single label. Note this returns the row as a Series.

>>> df.loc['viper']
max_speed    4
shield       5
Name: viper, dtype: Int64

List of labels. Note using [[]] returns a DataFrame.

>>> df.loc[['viper', 'sidewinder']]
            max_speed  shield
viper               4       5
sidewinder          7       8

[2 rows x 2 columns]

Slice with labels for row and single label for column. As mentioned above, note that both the start and stop of the slice are included.

>>> df.loc['cobra', 'shield']
np.int64(2)

Index (same behavior as df.reindex)

>>> df.loc[bpd.Index(["cobra", "viper"], name="foo")]
      max_speed  shield
cobra          1       2
viper          4       5

[2 rows x 2 columns]

Conditional that returns a boolean Series with column labels specified

>>> df.loc[df['shield'] > 6, ['max_speed']]
            max_speed
sidewinder          7

[1 rows x 1 columns]

Multiple conditional using | that returns a boolean Series

>>> df.loc[(df['max_speed'] > 4) | (df['shield'] < 5)]
            max_speed  shield
cobra               1       2
sidewinder          7       8

[2 rows x 2 columns]

Please ensure that each condition is wrapped in parentheses ().

Set value for an entire column

>>> df.loc[:, 'max_speed'] = 30
>>> df
            max_speed  shield
cobra              30       2
viper              30       5
sidewinder         30       8

[3 rows x 2 columns]
Returns:

Indexers object.

Return type:

bigframes.core.indexers.LocSeriesIndexer