pyspark.pandas.MultiIndex.insert

MultiIndex.insert(loc: int, item: Any) → pyspark.pandas.indexes.base.Index[source]

Make new MultiIndex inserting new item at location.

Follows Python list.append semantics for negative values.

Parameters
locint
itemobject
Returns
new_indexMultiIndex

Examples

>>> psmidx = ps.MultiIndex.from_tuples([("a", "x"), ("b", "y"), ("c", "z")])
>>> psmidx.insert(3, ("h", "j"))  
MultiIndex([('a', 'x'),
            ('b', 'y'),
            ('c', 'z'),
            ('h', 'j')],
           )

For negative values

>>> psmidx.insert(-2, ("h", "j"))  
MultiIndex([('a', 'x'),
            ('h', 'j'),
            ('b', 'y'),
            ('c', 'z')],
           )