Examine the default index of a pd.Series

The index of a pd.Series is of type pd.Index or one of the subclasses of pd.Index (pd.RangeIndex, pd.DatetimeIndex, pd.MultiIndex, etc). The default index is a pd.RangeIndex starting at 0, with a step of 1.

"Examine the default index of a pd.Series."

import sys
import pandas as pd

data = [0.0, 10.0, 20.0, 30.0, 40.0]
series = pd.Series(data = data, name = "temperature") #born with the default index
print(series)
print()

print(f"{series.index = }")
print(f"{type(series.index) = }")
print(f"{len(series.index) = }")
print(f"{series.index.name = }")
print(f"{series.index.dtype.name = }")
print()

print(series.index.array)
sys.exit(0)
0     0.0
1    10.0
2    20.0
3    30.0
4    40.0
Name: temperature, dtype: float64

series.index = RangeIndex(start=0, stop=5, step=1)
type(series.index) = <class 'pandas.core.indexes.range.RangeIndex'>
len(series.index) = 5
series.index.name = None
series.index.dtype.name = 'int64'

<PandasArray>
[0, 1, 2, 3, 4]
Length: 5, dtype: int64

Things to try

  1. Verify that the class of the default index (pd.RangeIndex) is a subclass of class pd.Index.
    print(f"{issubclass(type(series.index), pd.Index) = }")
    print()
    
    for t in type(series.index).mro():   #method resolution order
        print(t)
    
    issubclass(type(series.index), pd.Index) = True
    
    <class 'pandas.core.indexes.range.RangeIndex'>
    <class 'pandas.core.indexes.numeric.Int64Index'>
    <class 'pandas.core.indexes.numeric.IntegerIndex'>
    <class 'pandas.core.indexes.numeric.NumericIndex'>
    <class 'pandas.core.indexes.base.Index'>
    <class 'pandas.core.base.IndexOpsMixin'>
    <class 'pandas.core.base.PandasObject'>
    <class 'pandas.core.accessor.DirNamesMixin'>
    <class 'object'>