reindex_like
과 관련 기능을 사용할 때 Pandas Series 객체의 차이점에 대해 혼란스러워합니다. 예를 들어, 다음과 같은 일련의 객체를 고려해numpy.logical_and 및 Pandas Series 객체를 사용할 때의 AttributeError
x
에
>>> import numpy
>>> import pandas
>>> series = pandas.Series([1, 2, 3])
>>> x = pandas.Series([True]).reindex_like(series).fillna(True)
>>> y = pandas.Series(True, index=series.index)
>>> x
0 True
1 True
2 True
>>> y
0 True
1 True
2 True
및 y
은 그 내용과 색인에서 동일하게 나타납니다. 그러나 어떤 방법 으로든 차이가 발생해야하는데 그 이유 중 하나는 numpy.logical_and()
을 사용할 때 오류가 발생하고 다른 하나는 그렇지 않기 때문입니다.
>>> numpy.logical_and(series, y)
0 True
1 True
2 True
>>> numpy.logical_and(series, x)
Traceback (most recent call last):
File "<ipython-input-10-e2050a2015bf>", line 1, in <module>
numpy.logical_and(series, x)
AttributeError: logical_and
여기에 대해 numpy.logical()
은 무엇인가요? 두 시리즈의 차이점은 보이지 않습니다. x
및 y
. 그러나 약간의 차이가 있어야합니다.
판다 (Pandas) 문서는 Series 개체가 "대부분의 NumPy 함수"에 대한 유효한 인수라고 말합니다. 이것은 분명히 사실입니다. 분명히 생성 메카니즘은 x
을이 특별한 numpy 함수로 사용할 수 없게 만든다.
두 가지 생성 메커니즘 중 reindex_like()
과 index
인수 중 어떤 것이이 시나리오에서보다 효율적이고 관용적입니까? 아마 내가 고려하지 않은 또 다른/더 좋은 방법이있을 것입니다.
어떤 pandas/numpy/python 버전을 사용하고 있습니까? 'numpy.logical_and (series, x)'는'pandas-0.9.0-py2.7'에서 나를 위해 오류없이 작동합니다 ... –
pandas 0.9.1과 numpy 1.6.2를 사용하여 –
나는 이것이 놀랍습니다. pandas 0.9.1의 새로운 버그, 그러나 아마도 numpy 버전 1.8으로 업그레이드 할 가치가 있습니까? (내가 사용하고있는 버전은 작동하는 것처럼 보입니다 ...) –