Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

ENH: Allow unstacking by level name #142

Closed
wants to merge 1 commit into
from
Jump to file or symbol
Failed to load files and symbols.
+8 −2
Split
View
@@ -17,8 +17,8 @@ class _Unstacker(object):
Parameters
----------
- level : int, default last level
- Level to "unstack"
+ level : int or str, default last level
+ Level to "unstack". Accepts a name for the level.
Examples
--------
@@ -53,6 +53,12 @@ def __init__(self, values, index, level=-1, value_columns=None):
self.index = index
+ if not isinstance(level, int):
+ try:
+ level = index.names.index(level)
+ except:
+ raise ValueError("level %s not in index names" % s)
+
if level < 0:
level += index.nlevels
self.level = level