iatowks
iatowks

Reputation: 1040

How to remove the u' and some other information from Ipython/Pandas output

I've been reading the great Python for Data Analysis book and following its exercises along, but my outputs are not the same that the outputs shown in the book.

One of them happens when I want to print the indices of a data frame object. For example:

>>> data = Series(np.random.randn(10), index=[['a', 'a', 'a', 'b', 'b', 'b', 'c', 'c', 'd', 'd'],[1, 2, 3, 1, 2, 3, 1, 2, 2, 3]])

When I call data.index, I get a output different from the book. Here's the output shown in the book:

MultiIndex
[('a', 1) ('a', 2) ('a', 3) ('b', 1) ('b', 2) ('b', 3) ('c', 1)
('c', 2) ('d', 2) ('d', 3)] 

And this is my output:

MultiIndex(levels=[[u'a', u'b', u'c', u'd'], [1, 2, 3]],
       labels=[[0, 0, 0, 1, 1, 1, 2, 2, 3, 3], [0, 1, 2, 0, 1, 2, 0, 1, 1, 2]])

How do I configure either Ipython or Pandas to change the output formatting? At least the u' piece of string.

Edit: I'm using Python 2.7.

Upvotes: 0

Views: 732

Answers (1)

Colonel Beauvel
Colonel Beauvel

Reputation: 31181

You can have this display if you do a list conversion:

data.index.tolist()

#[('a', 1L), ('a', 2L), ('a', 3L), ('b', 1L), ('b', 2L), ('b', 3L), ('c', 1L), ('c', 2L), ('d', 2L), ('d', 3L)]

Upvotes: 2

Related Questions