bigframes.pandas.Series.loc#

propertySeries.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  shieldcobra               1       2viper               4       5sidewinder          7       8[3 rows x 2 columns]

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

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

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

>>>df.loc[['viper','sidewinder']]            max_speed  shieldviper               4       5sidewinder          7       8[2 rows x 2 columns]

Slice with labels for row and single label for column. As mentionedabove, 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  shieldcobra          1       2viper          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_speedsidewinder          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  shieldcobra               1       2sidewinder          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  shieldcobra              30       2viper              30       5sidewinder         30       8[3 rows x 2 columns]
Returns:

Indexers object.

Return type:

bigframes.core.indexers.LocSeriesIndexer

On this page

This Page