如何从 Ipython/Pandas 输出中删除 u' 和一些其他信息

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

我一直在阅读伟大的 Python 数据分析书并按照其中的练习进行操作,但我的输出与书中显示的输出不同。

其中一个发生在我想要打印数据框对象的索引时。例如:

>>> 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]])

当我调用 data.index 时,我得到了与书中不同的输出。这是书中显示的输出:

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

这是我的输出:

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]])

如何配置 Ipython 或 Pandas 以更改输出格式?至少 u' 段字符串。

编辑:我正在使用 Python 2.7.

如果您进行 list 转换,您可以拥有此显示:

data.index.tolist()

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