为什么我在这里收到错误?使用Python 2.6和pandas v.0.13.1
In [2]: df = pd.DataFrame({'x': [1, 1, 2, 2, 1, 1], 'y':[1, 2, 2, 2, 2, 1]})
In [3]: print pd.factorize(pd.lib.fast_zip([df.x, df.y]))[0]
---------------------------------------------------------------------------
SystemError Traceback (most recent call last)
<ipython-input-3-d98d985f2794> in <module>()
----> 1 print pd.factorize(pd.lib.fast_zip([df.x, df.y]))[0]
/usr/lib64/python2.6/site-packages/pandas/lib.so in pandas.lib.fast_zip (pandas/lib.c:8026)()
SystemError: numpy/core/src/multiarray/iterators.c:370: bad argument to internal function
答案 0 :(得分:2)
您必须使用df.x.values
和df.y.values
来访问np.ndarray
中所需的pd.lib.fast_zip()
个对象:
print(pd.factorize(pd.lib.fast_zip([df.x.values, df.y.values]))[0])