I'm having an issue slicing a pandas.MultiIndex Series in the research environment. The problem seems to be isolated to my research area, as I'm recycling code from a local project. The issue is demonstrated below (The code example is taken from jakevdp's website)
import pandas as pd import numpy as np index = pd.MultiIndex.from_product([[2013, 2014, 2015, 2016, 2017], [1, 2]], names=['year', 'visit']) columns = pd.MultiIndex.from_product([['Bob', 'Guido', 'Sue']]) # Fake data taken from the website referenced data = np.round(np.random.randn(10, 3), 1) data[:, ::2] *= 10 data += 37 # DataFrame health_data = pd.DataFrame(data, index=index, columns=columns) health_data # IndexSlice class for slicing MultiIndex Dataframe/Series idx = pd.IndexSlice dates = [2013, 2014] bob = health_data.iloc[:, 0] # The following should slice at dates bob.loc[idx[dates, :]]
This yields the following error
AttributeError: '_iLocIndexer' object has no attribute '_getitem_axis'
I can get around the issue by using
bob = health_data[['Bob']]instead, but I'm curious as to why this error is being raised when it's a valid operation?