DEV Community

Nilotpal Choudhury
Nilotpal Choudhury

Posted on • Updated on

Answer: Pandas: Get unique MultiIndex level values by label

Pandas 0.23.0 finally introduced a much cleaner solution to this problem: the level argument to Index.unique():

In [3]: df.index.unique(level='co')
Out[3]: Index(['DE', 'FR'], dtype='object', name='co')

This is now the recommended solution. It is far more efficient because it avoids creating a complete representation of the level values in memory, and…

Top comments (0)