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.
Changed in version 3.4.0: Raise IndexError when loc is out of bounds to follow Pandas 1.4+ behavior
- 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')], )