2
팬더에서 계층 형 색인 생성에 대해 documentation을 진행하고있었습니다. 나는 계층 인덱싱 빈 dataframe을 만드는 데에서 예제를 테스트하려고 :ValueError : Length mismatch : 팬더 데이터 프레임에 계층 형 열을 생성 할 때 예상 축에 요소가 0 개임
ValueError Traceback (most recent call last)
<ipython-input-6-dd823f9b8d22> in <module>()
----> 1 df.columns = pd.MultiIndex(levels = [['first', 'second'], ['a', 'b']], labels = [[0, 0, 1, 1], [0, 1, 0, 1]])
/usr/local/lib/python3.4/dist-packages/pandas/core/generic.py in __setattr__(self, name, value)
2755 try:
2756 object.__getattribute__(self, name)
-> 2757 return object.__setattr__(self, name, value)
2758 except AttributeError:
2759 pass
pandas/src/properties.pyx in pandas.lib.AxisProperty.__set__ (pandas/lib.c:44873)()
/usr/local/lib/python3.4/dist-packages/pandas/core/generic.py in _set_axis(self, axis, labels)
446
447 def _set_axis(self, axis, labels):
--> 448 self._data.set_axis(axis, labels)
449 self._clear_item_cache()
450
/usr/local/lib/python3.4/dist-packages/pandas/core/internals.py in set_axis(self, axis, new_labels)
2800 raise ValueError('Length mismatch: Expected axis has %d elements, '
2801 'new values have %d elements' %
-> 2802 (old_len, new_len))
2803
2804 self.axes[axis] = new_labels
ValueError: Length mismatch: Expected axis has 0 elements, new values have 4 elements
내 코드에 문제가 표시되지 않습니다
In [5]: df = pd.DataFrame()
In [6]: df.columns = pd.MultiIndex(levels = [['first', 'second'], ['a', 'b']], labels = [[0, 0, 1, 1], [0, 1, 0, 1]])
그러나,이 오류가 발생합니다. 어떤 아이디어가 발생하고 있습니까?
감사합니다! 제쳐두고, 나는 pd.np와 같은 것을 본 적이 없다. 이것에 대해 좀 더 자세히 설명해 주시겠습니까? – Peaceful
반갑습니다. 'pd.np'는'numpy as np import '의 짧은 손입니다. pandas.np' 모듈에서 numpy 모듈을 명시 적으로 임포트 할 필요없이 numpy 함수에 접근 할 수 있습니다. – Psidom