Class Index (2.0.0)

Index(data=None,dtype=None,*,name=None,session=None)

Immutable sequence used for indexing and alignment.

The basic object storing axis labels for all objects.

Parameters

NameDescription
datapandas.Series pandas.Index bigframes.series.Seriesbigframes.core.indexes.base.Index

Labels (1-dimensional).

sessionOptional[bigframes.session.Session]

BigQuery DataFrames session where queries are run. If not set, a default session is used.

Properties

T

Return the transpose, which is by definition self.

Examples:

>>> import bigframes.pandas as bpd >>> bpd.options.display.progress_bar = None >>> s = bpd.Series(['Ant', 'Bear', 'Cow']) >>> s 0 Ant 1 Bear 2 Cow dtype: string >>> s.T 0 Ant 1 Bear 2 Cow dtype: string 

For Index:

>>> idx = bpd.Index([1, 2, 3]) >>> idx.T Index([1, 2, 3], dtype='Int64') 
Returns
TypeDescription
bigframes.pandas.IndexIndex

dtype

Return the dtype object of the underlying data.

Examples:

>>> import bigframes.pandas as bpd >>> bpd.options.display.progress_bar = None >>> idx = bpd.Index([1, 2, 3]) >>> idx Index([1, 2, 3], dtype='Int64') >>> idx.dtype Int64Dtype() 

dtypes

Return the dtypes as a Series for the underlying MultiIndex.

Returns
TypeDescription
Pandas.SeriesPandas.Series of the MultiIndex dtypes.

empty

Returns True if the Index is empty, otherwise returns False.

has_duplicates

Check if the Index has duplicate values.

Examples:

>>> import bigframes.pandas as bpd >>> bpd.options.display.progress_bar = None >>> idx = bpd.Index([1, 5, 7, 7]) >>> bool(idx.has_duplicates) True >>> idx = bpd.Index([1, 5, 7]) >>> bool(idx.has_duplicates) False 
Returns
TypeDescription
boolWhether or not the Index has duplicate values.

is_monotonic_decreasing

Return a boolean if the values are equal or decreasing.

Examples:

>>> import bigframes.pandas as bpd >>> bpd.options.display.progress_bar = None >>> bool(bpd.Index([3, 2, 1]).is_monotonic_decreasing) True >>> bool(bpd.Index([3, 2, 2]).is_monotonic_decreasing) True >>> bool(bpd.Index([3, 1, 2]).is_monotonic_decreasing) False 
Returns
TypeDescription
boolTrue, if the values monotonically decreasing, otherwise False.

is_monotonic_increasing

Return a boolean if the values are equal or increasing.

Examples:

>>> import bigframes.pandas as bpd >>> bpd.options.display.progress_bar = None >>> bool(bpd.Index([1, 2, 3]).is_monotonic_increasing) True >>> bool(bpd.Index([1, 2, 2]).is_monotonic_increasing) True >>> bool(bpd.Index([1, 3, 2]).is_monotonic_increasing) False 
Returns
TypeDescription
boolTrue, if the values monotonically increasing, otherwise False.

is_unique

Return if the index has unique values.

Examples:

>>> import bigframes.pandas as bpd >>> bpd.options.display.progress_bar = None >>> idx = bpd.Index([1, 5, 7, 7]) >>> idx.is_unique False >>> idx = bpd.Index([1, 5, 7]) >>> idx.is_unique True 
Returns
TypeDescription
boolTrue if the index has unique values, otherwise False.

name

Returns Index name.

Examples:

>>> import bigframes.pandas as bpd >>> bpd.options.display.progress_bar = None >>> idx = bpd.Index([1, 2, 3], name='x') >>> idx Index([1, 2, 3], dtype='Int64', name='x') >>> idx.name 'x' 
Returns
TypeDescription
blocks.LabelIndex or MultiIndex name

names

Returns the names of the Index.

Returns
TypeDescription
Sequence[blocks.Label]A Sequence of Index or MultiIndex name

ndim

Number of dimensions of the underlying data, by definition 1.

Examples:

>>> import bigframes.pandas as bpd >>> bpd.options.display.progress_bar = None >>> s = bpd.Series(['Ant', 'Bear', 'Cow']) >>> s 0 Ant 1 Bear 2 Cow dtype: string >>> s.ndim 1 

For Index:

>>> idx = bpd.Index([1, 2, 3]) >>> idx Index([1, 2, 3], dtype='Int64') >>> idx.ndim 1 
Returns
TypeDescription
intNumber or dimensions.

nlevels

Integer number of levels in this MultiIndex

Examples:

>>> import bigframes.pandas as bpd >>> bpd.options.display.progress_bar = None >>> mi = bpd.MultiIndex.from_arrays([['a'], ['b'], ['c']]) >>> mi MultiIndex([('a', 'b', 'c')], ) >>> mi.nlevels 3 
Returns
TypeDescription
intNumber of levels.

query_job

BigQuery job metadata for the most recent query.

shape

Return a tuple of the shape of the underlying data.

Examples:

>>> import bigframes.pandas as bpd >>> bpd.options.display.progress_bar = None >>> idx = bpd.Index([1, 2, 3]) >>> idx Index([1, 2, 3], dtype='Int64') >>> idx.shape (3,) 
Returns
TypeDescription
Tuple[int]A Tuple of integers representing the shape.

size

Return the number of elements in the underlying data.

Examples:

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

For Series:

>>> s = bpd.Series(['Ant', 'Bear', 'Cow']) >>> s 0 Ant 1 Bear 2 Cow dtype: string 

For Index:

>>> idx = bpd.Index([1, 2, 3]) >>> idx Index([1, 2, 3], dtype='Int64') 
Returns
TypeDescription
intNumber of elements

values

Return an array representing the data in the Index.

Examples:

>>> import bigframes.pandas as bpd >>> bpd.options.display.progress_bar = None >>> idx = bpd.Index([1, 2, 3]) >>> idx Index([1, 2, 3], dtype='Int64') >>> idx.values array([1, 2, 3]) 
Returns
TypeDescription
arrayNumpy.ndarray or ExtensionArray

Methods

all

all()-> bool

Return whether all elements are Truthy.

Examples:

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

True, because nonzero integers are considered True.

>>> bool(bpd.Index([1, 2, 3]).all()) True False, because 0 is considered False. >>> bool(bpd.Index([0, 1, 2]).all()) False 
Exceptions
TypeDescription
TypeErrorMultiIndex with more than 1 level does not support all.
Returns
TypeDescription
boolA single element array-like may be converted to bool.

any

any()-> bool

Return whether any element is Truthy.

Examples:

>>> import bigframes.pandas as bpd >>> bpd.options.display.progress_bar = None >>> index = bpd.Index([0, 1, 2]) >>> bool(index.any()) True >>> index = bpd.Index([0, 0, 0]) >>> bool(index.any()) False 
Exceptions
TypeDescription
TypeErrorMultiIndex with more than 1 level does not support any.
Returns
TypeDescription
boolA single element array-like may be converted to bool.

argmax

argmax()-> int

Return int position of the largest value in the Series.

If the maximum is achieved in multiple locations, the first row position is returned.

Examples:

Consider dataset containing cereal calories

>>> import bigframes.pandas as bpd >>> bpd.options.display.progress_bar = None >>> s = bpd.Series({'Corn Flakes': 100.0, 'Almond Delight': 110.0, ... 'Cinnamon Toast Crunch': 120.0, 'Cocoa Puff': 110.0}) >>> s Corn Flakes 100.0 Almond Delight 110.0 Cinnamon Toast Crunch 120.0 Cocoa Puff 110.0 dtype: Float64 >>> int(s.argmax()) 2 >>> int(s.argmin()) 0 

The maximum cereal calories is the third element and the minimum cereal calories is the first element, since series is zero-indexed.

Returns
TypeDescription
intRow position of the maximum value.

argmin

argmin()-> int

Return int position of the smallest value in the series.

If the minimum is achieved in multiple locations, the first row position is returned.

Examples:

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

Consider dataset containing cereal calories

>>> s = bpd.Series({'Corn Flakes': 100.0, 'Almond Delight': 110.0, ... 'Cinnamon Toast Crunch': 120.0, 'Cocoa Puff': 110.0}) >>> s Corn Flakes 100.0 Almond Delight 110.0 Cinnamon Toast Crunch 120.0 Cocoa Puff 110.0 dtype: Float64 >>> int(s.argmax()) 2 >>> int(s.argmin()) 0 

The maximum cereal calories is the third element and the minimum cereal calories is the first element, since series is zero-indexed.

Returns
TypeDescription
intRow position of the minimum value.

astype

astype(dtype,*,errors:typing.Literal["raise","null"]="raise")-> bigframes.core.indexes.base.Index

Create an Index with values cast to dtypes.

The class of a new Index is determined by dtype. When conversion is impossible, a TypeError exception is raised.

Examples:

>>> import bigframes.pandas as bpd >>> bpd.options.display.progress_bar = None >>> idx = bpd.Index([1, 2, 3]) >>> idx Index([1, 2, 3], dtype='Int64') 
Parameters
NameDescription
dtypestr, data type, or pandas.ExtensionDtype

A dtype supported by BigQuery DataFrame include 'boolean', 'Float64', 'Int64', 'int64[pyarrow]', 'string', 'string[pyarrow]', 'timestamp[us, tz=UTC][pyarrow]', 'timestamp[us][pyarrow]', 'date32[day][pyarrow]', 'time64[us][pyarrow]'. A pandas.ExtensionDtype include pandas.BooleanDtype(), pandas.Float64Dtype(), pandas.Int64Dtype(), pandas.StringDtype(storage="pyarrow"), pd.ArrowDtype(pa.date32()), pd.ArrowDtype(pa.time64("us")), pd.ArrowDtype(pa.timestamp("us")), pd.ArrowDtype(pa.timestamp("us", tz="UTC")).

errors{'raise', 'null'}, default 'raise'

Control raising of exceptions on invalid data for provided dtype. If 'raise', allow exceptions to be raised if any value fails cast If 'null', will assign null value if value fails cast

Exceptions
TypeDescription
ValueErrorIf errors is not one of raise.
TypeErrorMultiIndex with more than 1 level does not support astype.
Returns
TypeDescription
bigframes.pandas.IndexIndex with values cast to specified dtype.

copy

copy(name:typing.Optional[typing.Hashable]=None)

Make a copy of this object.

Name is set on the new object.

Examples:

>>> import bigframes.pandas as bpd >>> bpd.options.display.progress_bar = None >>> idx = bpd.Index(['a', 'b', 'c']) >>> new_idx = idx.copy() >>> idx is new_idx False 
Parameter
NameDescription
nameLabel, optional

Set name for new object.

Returns
TypeDescription
bigframes.pandas.IndexIndex reference to new object, which is a copy of this object.

drop

drop(labels:typing.Any)-> bigframes.core.indexes.base.Index

Make new Index with passed list of labels deleted.

Examples:

>>> import bigframes.pandas as bpd >>> bpd.options.display.progress_bar = None >>> idx = bpd.Index(['a', 'b', 'c']) >>> idx.drop(['a']) Index(['b', 'c'], dtype='string') 
Returns
TypeDescription
bigframes.pandas.IndexWill be same type as self.

drop_duplicates

drop_duplicates(*,keep:str="first")-> bigframes.core.indexes.base.Index

Return Index with duplicate values removed.

Examples:

>>> import bigframes.pandas as bpd >>> bpd.options.display.progress_bar = None Generate an pandas.Index with duplicate values. >>> idx = bpd.Index(['lama', 'cow', 'lama', 'beetle', 'lama', 'hippo']) 

The keep parameter controls which duplicate values are removed. The value first keeps the first occurrence for each set of duplicated entries. The default value of keep is first.

>>> idx.drop_duplicates(keep='first') Index(['lama', 'cow', 'beetle', 'hippo'], dtype='string') 

The value last keeps the last occurrence for each set of duplicated entries.

>>> idx.drop_duplicates(keep='last') Index(['cow', 'beetle', 'lama', 'hippo'], dtype='string') 

The value False discards all sets of duplicated entries.

>>> idx.drop_duplicates(keep=False) Index(['cow', 'beetle', 'hippo'], dtype='string') 
Parameter
NameDescription
keep{'first', 'last', False}, default 'first'

One of: 'first' : Drop duplicates except for the first occurrence. 'last' : Drop duplicates except for the last occurrence. False : Drop all duplicates.

dropna

dropna(how:typing.Literal["all","any"]="any",)-> bigframes.core.indexes.base.Index

Return Index without NA/NaN values.

Examples:

>>> import bigframes.pandas as bpd >>> import numpy as np >>> bpd.options.display.progress_bar = None >>> idx = bpd.Index([1, np.nan, 3]) >>> idx.dropna() Index([1.0, 3.0], dtype='Float64') 
Parameter
NameDescription
how{'any', 'all'}, default 'any'

If the Index is a MultiIndex, drop the value when any or all levels are NaN.

Exceptions
TypeDescription
ValueErrorIf how is not any or all

fillna

fillna(value=None)-> bigframes.core.indexes.base.Index

Fill NA/NaN values with the specified value.

Examples:

>>> import bigframes.pandas as bpd >>> import numpy as np >>> bpd.options.display.progress_bar = None >>> idx = bpd.Index([np.nan, np.nan, 3]) >>> idx.fillna(0) Index([0.0, 0.0, 3.0], dtype='Float64') 
Parameter
NameDescription
valuescalar

Scalar value to use to fill holes (e.g. 0). This value cannot be a list-likes.

Exceptions
TypeDescription
TypeErrorMultiIndex with more than 1 level does not support fillna.

from_frame

from_frame(frame:typing.Union[bigframes.series.Series,bigframes.dataframe.DataFrame],)-> bigframes.core.indexes.base.Index

Make a MultiIndex from a DataFrame.

Examples:

>>> import bigframes.pandas as bpd >>> bpd.options.display.progress_bar = None >>> df = bpd.DataFrame([['HI', 'Temp'], ['HI', 'Precip'], ... ['NJ', 'Temp'], ['NJ', 'Precip']], ... columns=['a', 'b']) >>> df a b 0 HI Temp 1 HI Precip 2 NJ Temp 3 NJ Precip <BLANKLINE> [4 rows x 2 columns] >>> bpd.MultiIndex.from_frame(df) Index([0, 1, 2, 3], dtype='Int64') 
Parameter
NameDescription
frameUnion[bigframes.pandas.Series, bigframes.pandas.DataFrame]

bigframes.pandas.Series or bigframes.pandas.DataFrame to convert to bigframes.pandas.Index.

Exceptions
TypeDescription
bigframes.exceptions.NullIndexErrorIf Index is Null.
Returns
TypeDescription
bigframes.pandas.IndexThe Index representation of the given Series or DataFrame.

get_level_values

get_level_values(level)-> bigframes.core.indexes.base.Index

Return an Index of values for requested level.

This is primarily useful to get an individual level of values from a MultiIndex, but is provided on Index as well for compatibility.

Examples:

>>> import bigframes.pandas as bpd >>> bpd.options.display.progress_bar = None >>> idx = bpd.Index(list('abc')) >>> idx Index(['a', 'b', 'c'], dtype='string') 

Get level values by supplying level as integer:

>>> idx.get_level_values(0) Index(['a', 'b', 'c'], dtype='string') 
Parameter
NameDescription
levelint or str

It is either the integer position or the name of the level.

Returns
TypeDescription
bigframes.pandas.IndexCalling object, as there is only one level in the Index.

isin

isin(values)-> bigframes.core.indexes.base.Index

Return a boolean array where the index values are in values.

Compute boolean array to check whether each index value is found in the passed set of values. The length of the returned boolean array matches the length of the index.

Examples:

>>> import bigframes.pandas as bpd >>> bpd.options.display.progress_bar = None >>> idx = bpd.Index([1,2,3]) >>> idx Index([1, 2, 3], dtype='Int64') 

Check whether each index value in a list of values.

>>> idx.isin([1, 4]) Index([True, False, False], dtype='boolean') >>> midx = bpd.MultiIndex.from_arrays([[1,2,3], ... ['red', 'blue', 'green']], ... names=('number', 'color')) >>> midx MultiIndex([(1, 'red'), (2, 'blue'), (3, 'green')], names=['number', 'color']) 
Parameter
NameDescription
valuesset or list-like

Sought values.

Exceptions
TypeDescription
TypeErrorIf object passed to isin() is not a list-like
Returns
TypeDescription
bigframes.pandas.SeriesSeries of boolean values.

max

max()-> typing.Any

Return the maximum value of the Index.

Examples:

>>> import bigframes.pandas as bpd >>> bpd.options.display.progress_bar = None >>> idx = bpd.Index([3, 2, 1]) >>> int(idx.max()) 3 >>> idx = bpd.Index(['c', 'b', 'a']) >>> idx.max() 'c' 
Returns
TypeDescription
scalarMaximum value.

min

min()-> typing.Any

Return the minimum value of the Index.

Examples:

>>> import bigframes.pandas as bpd >>> bpd.options.display.progress_bar = None >>> idx = bpd.Index([3, 2, 1]) >>> int(idx.min()) 1 >>> idx = bpd.Index(['c', 'b', 'a']) >>> idx.min() 'a' 
Returns
TypeDescription
scalarMinimum value.

nunique

nunique()-> int

Return number of unique elements in the object.

Excludes NA values by default.

Examples:

>>> import bigframes.pandas as bpd >>> bpd.options.display.progress_bar = None >>> s = bpd.Series([1, 3, 5, 7, 7]) >>> s 0 1 1 3 2 5 3 7 4 7 dtype: Int64 >>> int(s.nunique()) 4 
Returns
TypeDescription
intNumber of unique elements

rename

rename(name:typing.Union[str,typing.Sequence[str]],)-> bigframes.core.indexes.base.Index

Alter Index or MultiIndex name.

Able to set new names without level. Defaults to returning new index. Length of names must match number of levels in MultiIndex.

Examples:

>>> import bigframes.pandas as bpd >>> bpd.options.display.progress_bar = None >>> idx = bpd.Index(['A', 'C', 'A', 'B'], name='score') >>> idx.rename('grade') Index(['A', 'C', 'A', 'B'], dtype='string', name='grade') 
Parameter
NameDescription
namelabel or list of labels

Name(s) to set.

Exceptions
TypeDescription
ValueErrorIf name is not the same length as levels.
Returns
TypeDescription
bigframes.pandas.IndexThe same type as the caller.

sort_values

sort_values(*,ascending:bool=True,na_position:str="last")

Return a sorted copy of the index.

Return a sorted copy of the index, and optionally return the indices that sorted the index itself.

Examples:

>>> import bigframes.pandas as bpd >>> bpd.options.display.progress_bar = None >>> idx = bpd.Index([10, 100, 1, 1000]) >>> idx Index([10, 100, 1, 1000], dtype='Int64') 

Sort values in ascending order (default behavior).

>>> idx.sort_values() Index([1, 10, 100, 1000], dtype='Int64') 
Parameters
NameDescription
ascendingbool, default True

Should the index values be sorted in an ascending order.

na_position{'first' or 'last'}, default 'last'

Argument 'first' puts NaNs at the beginning, 'last' puts NaNs at the end.

Exceptions
TypeDescription
ValueErrorIf no_position is not one of first or last.
Returns
TypeDescription
pandas.IndexSorted copy of the index.

to_numpy

to_numpy(dtype=None,*,allow_large_results=None,**kwargs)-> numpy.ndarray

A NumPy ndarray representing the values in this Series or Index.

Parameter
NameDescription
allow_large_resultsbool, default None

If not None, overrides the global setting to allow or disallow large query results over the default size limit of 10 GB.

to_pandas

Gets the Index as a pandas Index.

Parameters
NameDescription
allow_large_resultsbool, default None

If not None, overrides the global setting to allow or disallow large query results over the default size limit of 10 GB.

dry_runbool, default False

If this argument is true, this method will not process the data. Instead, it returns a Pandas series containing dtype and the amount of bytes to be processed.

Returns
TypeDescription
pandas.Index pandas.SeriesA pandas Index with all of the labels from this Index. If dry run is set to True, returns a Series containing dry run statistics.

to_series

to_series(index:typing.Optional[bigframes.core.indexes.base.Index]=None,name:typing.Optional[typing.Hashable]=None,)-> bigframes.series.Series

Create a Series with both index and values equal to the index keys.

Useful with map for returning an indexer based on an index.

Examples:

>>> import bigframes.pandas as bpd >>> bpd.options.display.progress_bar = None >>> idx = bpd.Index(['Ant', 'Bear', 'Cow'], name='animal') 

By default, the original index and original name is reused.

>>> idx.to_series() animal Ant Ant Bear Bear Cow Cow Name: animal, dtype: string 

To enforce a new index, specify new labels to index:

>>> idx.to_series(index=[0, 1, 2]) 0 Ant 1 Bear 2 Cow Name: animal, dtype: string 

To override the name of the resulting column, specify name:

>>> idx.to_series(name='zoo') animal Ant Ant Bear Bear Cow Cow Name: zoo, dtype: string 
Parameters
NameDescription
indexIndex, optional

Index of resulting Series. If None, defaults to original index.

namestr, optional

Name of resulting Series. If None, defaults to name of original index.

Returns
TypeDescription
bigframes.pandas.SeriesThe dtype will be based on the type of the Index values.

transpose

transpose()-> bigframes.core.indexes.base.Index

Return the transpose, which is by definition self.

value_counts

value_counts(normalize:bool=False,sort:bool=True,ascending:bool=False,*,dropna:bool=True)

Return a Series containing counts of unique values.

The resulting object will be in descending order so that the first element is the most frequently-occurring element. Excludes NA values by default.

Examples:

>>> import bigframes.pandas as bpd >>> import numpy as np >>> bpd.options.display.progress_bar = None >>> index = bpd.Index([3, 1, 2, 3, 4, np.nan]) >>> index.value_counts() 3.0 2 1.0 1 2.0 1 4.0 1 Name: count, dtype: Int64 

With normalize set to True, returns the relative frequency by dividing all values by the sum of values.

>>> s = bpd.Series([3, 1, 2, 3, 4, np.nan]) >>> s.value_counts(normalize=True) 3.0 0.4 1.0 0.2 2.0 0.2 4.0 0.2 Name: proportion, dtype: Float64 

dropna

With dropna set to False we can also see NaN index values.

>>> s.value_counts(dropna=False) 3.0 2 1.0 1 2.0 1 4.0 1 <NA> 1 Name: count, dtype: Int64 
Parameters
NameDescription
normalizebool, default False

If True, then the object returned will contain the relative frequencies of the unique values.

sortbool, default True

Sort by frequencies.

ascendingbool, default False

Sort in ascending order.

dropnabool, default True

Don't include counts of NaN.