Cannot index with multidimensional key error

What does cannot index with multidimensional key mean? Tried to change avg_wins.ix to avg_wins.loc but no luck. How do I correct this issue?

1

1 Answer

It looks like this is from pandas or dask. It pops up when you try to .loc (locate) from a pd.DataFrame or dd.DataFrame, which has a MultiIndex column.

Your output should look like this:

df.columns
MultiIndex([( 'A', 'first'), ( 'B', 'first'), ( 'C', 'mean')])

and so on. Otherwise it will simply output a flat list of columns.

So in a MultiIndex you can do different things, but what helps is to know how you can .loc (locate/filter) pretty easy:

df['A','first']

will give you that column and

df.loc[df['A','first'] == 5]

let you filter over a MultiIndex column.

Dask: MultIndex is used as default in dask groupby functions, when using multiple aggregate functions for one column, like this:

my_aggregate = { 'A': 'first', 'B': 'first', 'C': ['mean','last'],

TL;DR: Look for a pandas/dask MultiIndex column.

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like