I'm a newbie trying to go through Python for Data Analysis. I've been able to follow along and think Pandas is fantastic.
However, the example on page 127 uses the deprecated .ix
method and I've tried to rework it a couple of times and am stumped.
Primarily I referenced the thorough explanation here: How are Pandas iloc, ix and loc different and related?
Specifically the section titled 'Simultaneous selection with labels and integer location'
Here's the example in the book:
data = DataFrame(np.arange(16).reshape((4, 4)),
index=['Ohio', 'Colorado', 'Utah', 'New York'],
columns=['one', 'two', 'three', 'four'])
[In]: data.ix[['Colorado', 'Utah'], [3, 0, 1]]
[Out]:
four one two
Colorado 7 0 5
Utah 11 8 9
And here's my example, based of the SO article, that I can't get to work:
labels = ['Colorado','Utah']
ind_names = data.index.get_loc()
index_ints = [df.index.get_loc(label) for label in labels]
print(data.iloc[index_ints,[3,0,1]])
Thank you for your help.