使用分类变量打印pandas.DataFrame会引发IndexError ...这是一个错误吗?

时间:2015-10-19 22:38:32

标签: python pandas

我尝试将pandas.DataFrame与分类变量一起使用。我可以很好地创建DataFrame,但是当我尝试打印它时,我得到了IndexError ...我做错了什么或者pandas中有错误吗?

Python 2.7.6 (default, Nov 10 2013, 19:24:24) [MSC v.1500 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import pandas as pd
>>> bb=pd.Categorical(["a"]*1000,categories=["a","b","c"],ordered=False)
>>> cc=pd.Categorical(["b"]*1000,categories=["a","b","c"],ordered=False)
>>> aa=pd.DataFrame(); aa['bb']=bb; aa['cc']=cc;
>>> aa
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Python27\lib\site-packages\pandas\core\base.py", line 66, in __repr__
    return str(self)
  File "C:\Python27\lib\site-packages\pandas\core\base.py", line 46, in __str__
    return self.__bytes__()
  File "C:\Python27\lib\site-packages\pandas\core\base.py", line 58, in __bytes__
    return self.__unicode__().encode(encoding, 'replace')
  File "C:\Python27\lib\site-packages\pandas\core\frame.py", line 504, in __unicode__
    line_width=width, show_dimensions=show_dimensions)
  File "C:\Python27\lib\site-packages\pandas\core\frame.py", line 1335, in to_string
    show_dimensions=show_dimensions)
  File "C:\Python27\lib\site-packages\pandas\core\format.py", line 347, in __init__
    self._chk_truncate()
  File "C:\Python27\lib\site-packages\pandas\core\format.py", line 412, in _chk_truncate
    frame = concat((frame.iloc[:row_num, :], frame.iloc[-row_num:, :]))
  File "C:\Python27\lib\site-packages\pandas\tools\merge.py", line 755, in concat
    return op.get_result()
  File "C:\Python27\lib\site-packages\pandas\tools\merge.py", line 926, in get_result
    mgrs_indexers, self.new_axes, concat_axis=self.axis, copy=self.copy)
  File "C:\Python27\lib\site-packages\pandas\core\internals.py", line 4040, in concatenate_block_managers
    for placement, join_units in concat_plan]
  File "C:\Python27\lib\site-packages\pandas\core\internals.py", line 4141, in concatenate_join_units
    concat_values = com._concat_compat(to_concat, axis=concat_axis)
  File "C:\Python27\lib\site-packages\pandas\core\common.py", line 2950, in _concat_compat
    return _concat_compat(to_concat, axis=axis)
  File "C:\Python27\lib\site-packages\pandas\core\categorical.py", line 1673, in _concat_compat
    return Categorical(np.concatenate([ convert_categorical(x) for x in to_concat ],axis=axis), categories=categories)
IndexError: axis 1 out of bounds [0, 1)
>>>

1 个答案:

答案 0 :(得分:0)

问题已在pandas 0.17.0

中修复