0

I have been unsuccessful in reproducing the hierarchical indexing example on page 148 of Wes McKinney's "Python for Data Analysis" book. I am currently using python 2.7 on Mac OS X 10.8.2. (I have the same problem on ubuntu precise as well with pandas 0.7-0.10).

Any and all help is appreciated.

frame = pd.DataFrame(np.arange(12).reshape((4, 3)), index = list('aabb'), 
                  columns = [['Ohio', 'Ohio', 'Colorado']['Green', 'Red', 'Green']])  

Error message:

TypeError                                 Traceback (most recent call last)
<ipython-input-27-681f4740a561> in <module>()
      1 frame = pd.DataFrame(np.arange(12).reshape((4, 3)), index = list('aabb'), 
----> 2                   columns = [['Ohio', 'Ohio', 'Colorado']['Green', 'Red', 'Green']])  

TypeError: list indices must be integers, not tuple

FYI I am using version 0.9 of the pandas library:

pd.__version__
'0.9.0rc1'
2
  • thanks @hayden for editing my question /formatting the code.. Commented Dec 31, 2012 at 23:03
  • FYI, pandas official 0.10.0 is out since end of December. Commented Jan 6, 2013 at 6:52

1 Answer 1

1

I don't have the book, but it looks like you left out a comma:

frame = pd.DataFrame(np.arange(12).reshape((4, 3)), index = list('aabb'), columns = [['Ohio', 'Ohio', 'Colorado'], ['Green', 'Red', 'Green']])

Note the comma between 'Colorado'] and ['Green'.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.