I am using a pandas.Series with a MultiIndex for a bidirectional weighted lookup. I thought it should be easy to also find the corresponding other levels for a given level using the MultiIndex, but I cannot find a simple function other that does something like the following:
>>> index=pandas.MultiIndex.from_tuples(
... [(0, 0),(1,2),(3,4),(5,6),(5,7),(8,0),(9,0)],
... names=["concept", "word"])
>>> other(index, "word", 0)
{0, 8, 9}
>>> other(index, "concept", 3)
{4}
>>> other(index, "word", 6)
{5}
I'm happy to specify level numbers instead of level names and to get any iterable out, not necessarily a set. I only have a 2-level multi-index, so I don't care about how to generalize to a higher-level multi-indices, or even whether it does generalize.
I would be slightly unhappy if this involves iterating over all entries in the MultiIndex and comparing them, because I thought indices are somewhat like multi-key hash tables.