pyspark.pandas.Series.droplevel¶
-
Series.
droplevel
(level: Union[int, Any, Tuple[Any, …], List[Union[int, Any, Tuple[Any, …]]]]) → pyspark.pandas.series.Series¶ Return Series with requested index level(s) removed.
- Parameters
- levelint, str, or list-like
If a string is given, must be the name of a level If list-like, elements must be names or positional indexes of levels.
- Returns
- Series
Series with requested index level(s) removed.
Examples
>>> psser = ps.Series( ... [1, 2, 3], ... index=pd.MultiIndex.from_tuples( ... [("x", "a"), ("x", "b"), ("y", "c")], names=["level_1", "level_2"] ... ), ... ) >>> psser level_1 level_2 x a 1 b 2 y c 3 dtype: int64
Removing specific index level by level
>>> psser.droplevel(0) level_2 a 1 b 2 c 3 dtype: int64
Removing specific index level by name
>>> psser.droplevel("level_2") level_1 x 1 x 2 y 3 dtype: int64