pyspark.pandas.DataFrame.droplevel

DataFrame.droplevel(level: Union[int, Any, Tuple[Any, …], List[Union[int, Any, Tuple[Any, …]]]], axis: Union[int, str] = 0) → pyspark.pandas.frame.DataFrame[source]

Return DataFrame with requested index / column level(s) removed.

Parameters
level: int, 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.

axis: {0 or ‘index’, 1 or ‘columns’}, default 0
Returns
DataFrame with requested index / column level(s) removed.

Examples

>>> df = ps.DataFrame(
...     [[3, 4], [7, 8], [11, 12]],
...     index=pd.MultiIndex.from_tuples([(1, 2), (5, 6), (9, 10)], names=["a", "b"]),
... )
>>> df.columns = pd.MultiIndex.from_tuples([
...   ('c', 'e'), ('d', 'f')
... ], names=['level_1', 'level_2'])
>>> df  
level_1   c   d
level_2   e   f
a b
1 2      3   4
5 6      7   8
9 10    11  12
>>> df.droplevel('a')  
level_1   c   d
level_2   e   f
b
2        3   4
6        7   8
10      11  12
>>> df.droplevel('level_2', axis=1)  
level_1   c   d
a b
1 2      3   4
5 6      7   8
9 10    11  12