pandas.Index#
- class pandas.Index(data=None, dtype=None, copy=False, name=None, tupleize_cols=True, **kwargs)[source]#
Immutable sequence used for indexing and alignment.
The basic object storing axis labels for all pandas objects.
- Parameters
- dataarray-like (1-dimensional)
- dtypeNumPy dtype (default: object)
If dtype is None, we find the dtype that best fits the data. If an actual dtype is provided, we coerce to that dtype if it’s safe. Otherwise, an error will be raised.
- copybool
Make a copy of input ndarray.
- nameobject
Name to be stored in the index.
- tupleize_colsbool (default: True)
When True, attempt to create a MultiIndex if possible.
See also
RangeIndex
Index implementing a monotonic integer range.
CategoricalIndex
Index of
Categorical
s.MultiIndex
A multi-level, or hierarchical Index.
IntervalIndex
An Index of
Interval
s.DatetimeIndex
Index of datetime64 data.
TimedeltaIndex
Index of timedelta64 data.
PeriodIndex
Index of Period data.
NumericIndex
Index of numpy int/uint/float data.
Int64Index
Index of purely int64 labels (deprecated).
UInt64Index
Index of purely uint64 labels (deprecated).
Float64Index
Index of purely float64 labels (deprecated).
Notes
An Index instance can only contain hashable objects
Examples
>>> pd.Index([1, 2, 3]) Int64Index([1, 2, 3], dtype='int64')
>>> pd.Index(list('abc')) Index(['a', 'b', 'c'], dtype='object')
Attributes
Return the transpose, which is by definition self.
The ExtensionArray of the data backing this Series or Index.
Integer representation of the values.
Return the dtype object of the underlying data.
Check if the Index has duplicate values.
Return True if there are any NaNs.
Return a string of the type inferred from the values.
Whether or not the index values only consist of dates.
(DEPRECATED) Alias for is_monotonic_increasing.
Return a boolean if the values are equal or decreasing.
Return a boolean if the values are equal or increasing.
Return if the index has unique values.
Return Index or MultiIndex name.
Return the number of bytes in the underlying data.
Number of dimensions of the underlying data, by definition 1.
Number of levels.
Return a tuple of the shape of the underlying data.
Return the number of elements in the underlying data.
Return an array representing the data in the Index.
empty
names
Methods
all
(*args, **kwargs)Return whether all elements are Truthy.
any
(*args, **kwargs)Return whether any element is Truthy.
append
(other)Append a collection of Index options together.
argmax
([axis, skipna])Return int position of the largest value in the Series.
argmin
([axis, skipna])Return int position of the smallest value in the Series.
argsort
(*args, **kwargs)Return the integer indices that would sort the index.
asof
(label)Return the label from the index, or, if not present, the previous one.
asof_locs
(where, mask)Return the locations (indices) of labels in the index.
astype
(dtype[, copy])Create an Index with values cast to dtypes.
copy
([name, deep, dtype, names])Make a copy of this object.
delete
(loc)Make new Index with passed location(-s) deleted.
difference
(other[, sort])Return a new Index with elements of index not in other.
drop
(labels[, errors])Make new Index with passed list of labels deleted.
drop_duplicates
([keep])Return Index with duplicate values removed.
droplevel
([level])Return index with requested level(s) removed.
dropna
([how])Return Index without NA/NaN values.
duplicated
([keep])Indicate duplicate index values.
equals
(other)Determine if two Index object are equal.
factorize
([sort, na_sentinel, use_na_sentinel])Encode the object as an enumerated type or categorical variable.
fillna
([value, downcast])Fill NA/NaN values with the specified value.
format
([name, formatter, na_rep])Render a string representation of the Index.
get_indexer
(target[, method, limit, tolerance])Compute indexer and mask for new index given the current index.
get_indexer_for
(target)Guaranteed return of an indexer even when non-unique.
get_indexer_non_unique
(target)Compute indexer and mask for new index given the current index.
get_level_values
(level)Return an Index of values for requested level.
get_loc
(key[, method, tolerance])Get integer location, slice or boolean mask for requested label.
get_slice_bound
(label, side[, kind])Calculate slice bound that corresponds to given label.
get_value
(series, key)Fast lookup of value from 1-dimensional ndarray.
groupby
(values)Group the index labels by a given array of values.
Whether the type is an integer type.
identical
(other)Similar to equals, but checks that object attributes and types are also equal.
insert
(loc, item)Make new Index inserting new item at location.
intersection
(other[, sort])Form the intersection of two Index objects.
is_
(other)More flexible, faster check like
is
but that works through views.Check if the Index only consists of booleans.
Check if the Index holds categorical data.
Check if the Index is a floating type.
Check if the Index only consists of integers.
Check if the Index holds Interval objects.
is_mixed
()Check if the Index holds data with mixed data types.
Check if the Index only consists of numeric data.
Check if the Index is of the object dtype.
is_type_compatible
(kind)Whether the index type is compatible with the provided type.
isin
(values[, level])Return a boolean array where the index values are in values.
isna
()Detect missing values.
isnull
()Detect missing values.
item
()Return the first element of the underlying data as a Python scalar.
join
(other[, how, level, return_indexers, sort])Compute join_index and indexers to conform data structures to the new index.
map
(mapper[, na_action])Map values using an input mapping or function.
max
([axis, skipna])Return the maximum value of the Index.
memory_usage
([deep])Memory usage of the values.
min
([axis, skipna])Return the minimum value of the Index.
notna
()Detect existing (non-missing) values.
notnull
()Detect existing (non-missing) values.
nunique
([dropna])Return number of unique elements in the object.
putmask
(mask, value)Return a new Index of the values set with the mask.
ravel
([order])Return an ndarray of the flattened values of the underlying data.
reindex
(target[, method, level, limit, ...])Create index with target's values.
rename
(name[, inplace])Alter Index or MultiIndex name.
repeat
(repeats[, axis])Repeat elements of a Index.
searchsorted
(value[, side, sorter])Find indices where elements should be inserted to maintain order.
set_names
(names[, level, inplace])Set Index or MultiIndex name.
set_value
(arr, key, value)(DEPRECATED) Fast lookup of value from 1-dimensional ndarray.
shift
([periods, freq])Shift index by desired number of time frequency increments.
slice_indexer
([start, end, step, kind])Compute the slice indexer for input labels and step.
slice_locs
([start, end, step, kind])Compute slice locations for input labels.
sort
(*args, **kwargs)Use sort_values instead.
sort_values
([return_indexer, ascending, ...])Return a sorted copy of the index.
sortlevel
([level, ascending, sort_remaining])For internal compatibility with the Index API.
alias of
pandas.core.strings.accessor.StringMethods
symmetric_difference
(other[, result_name, sort])Compute the symmetric difference of two Index objects.
take
(indices[, axis, allow_fill, fill_value])Return a new Index of the values selected by the indices.
Identity method.
to_frame
([index, name])Create a DataFrame with a column containing the Index.
to_list
()Return a list of the values.
to_native_types
([slicer])(DEPRECATED) Format specified values of self and return them.
to_numpy
([dtype, copy, na_value])A NumPy ndarray representing the values in this Series or Index.
to_series
([index, name])Create a Series with both index and values equal to the index keys.
tolist
()Return a list of the values.
transpose
(*args, **kwargs)Return the transpose, which is by definition self.
union
(other[, sort])Form the union of two Index objects.
unique
([level])Return unique values in the index.
value_counts
([normalize, sort, ascending, ...])Return a Series containing counts of unique values.
where
(cond[, other])Replace values where the condition is False.
view