2013-03-01 3 views
0

팬더 문서에서 코드 샘플을 실행할 때 오류가 발생합니다.팬더 Timedelta 오류

내가 사용하고있는 판다의 버전과 관련이 있다고 생각되지만 그 사실을 확인할 수는 없습니다. 이

td = Series([ timedelta(days=i) for i in range(3) ]) 
td 
Out[53]: 
0   0:00:00 
1  1 day, 0:00:00 
2 2 days, 0:00:00 

df = DataFrame(dict(A = s, B = td)) 
df 
Out[54]: 
        A    B 
0 2012-01-01 00:00:00   0:00:00 
1 2012-01-02 00:00:00 1 day, 0:00:00 
2 2012-01-03 00:00:00 2 days, 0:00:00 

이 일관성이 될 것으로 보인다처럼

pandas - Time Deltas

from datetime import datetime, timedelta 
from pandas import * 

s = Series(date_range('2012-1-1', periods=3, freq='D')) 
s 

Out[52]: 
0 2012-01-01 00:00:00 
1 2012-01-02 00:00:00 
2 2012-01-03 00:00:00 

작동 :

pandas VERSION 0.10.1 
numpy VERSION 1.7.0 
scipy VERSION 0.12.0.dev-14b1e07 

아래의 예

여기 팬더 문서에서 직접 촬영 기대와 함께 ed 출력을 참조하십시오.

df['C'] = df['A'] + df['B'] 

...

--------------------------------------------------------------------------- 
TypeError         Traceback (most recent call last) 
<ipython-input-55-7057e174d79e> in <module>() 
----> 1 df['C'] = df['A'] + df['B'] 

/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pandas/core/series.pyc in wrapper(self, other) 
    91    if self.index.equals(other.index): 
    92     name = _maybe_match_name(self, other) 
---> 93     return Series(wrap_results(na_op(lvalues, rvalues)), 
    94        index=self.index, name=name) 
    95 

/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pandas/core/series.pyc in na_op(x, y) 
    63    if isinstance(y, np.ndarray): 
    64     mask = notnull(x) & notnull(y) 
---> 65     result[mask] = op(x[mask], y[mask]) 
    66    else: 
    67     mask = notnull(x) 

TypeError: ufunc add cannot use operands with types dtype('<M8[ns]') and dtype('O') 

데이터 유형 :

샘플 코드의 다음 줄에 오류가 산출 내가 할 때 마찬가지로

df.dtypes 

Out[56]: 
A datetime64[ns] 
B   object 

을, 오류가 발생합니다 덧셈/뺄셈 :

s - s.max() 

<ipython-input-57-8d53e24db927> in <module>() 
----> 1 s - s.max() 

/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pandas/core/series.pyc in wrapper(self, other) 
    78 
    79   if (com.is_datetime64_dtype(self) and 
---> 80    com.is_datetime64_dtype(other)): 
    81    lvalues = lvalues.view('i8') 
    82    rvalues = rvalues.view('i8') 

/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pandas/core/common.pyc in is_datetime64_dtype(arr_or_dtype) 
    1003   tipo = arr_or_dtype.type 
    1004  else: 
-> 1005   tipo = arr_or_dtype.dtype.type 
    1006  return issubclass(tipo, np.datetime64) 
    1007 

AttributeError: 'Timestamp' object has no attribute 'dtype' 

이 코드는 참고 용으로 개략적으로 표시되어 있습니다. 어떤 도움이나 제안에 대한

https://gist.github.com/hernamesbarbara/5061972

감사합니다; 대단히 감사합니다.

당신은 페이지의 제목에 당신이 연결하고 (브라우저 창의 상단)를 보면

답변

1

오스틴

, 당신이 팬더의 개발 버전의 것을 볼 수 있습니다 그래서 http://pandas.pydata.org/pandas-docs/dev/timeseries.html#time-deltas

, 오늘은 버전 번호

'0.11.0.dev-13ae597' 

이 코드는 잘 작동합니다.

안정 버전에 대한 문서는 여기에 있습니다 :

http://pandas.pydata.org/pandas-docs/stable/

어디 당신이 당신의 버전 브라우저 창

pandas 0.10.1 

의 상단에 표시됩니다.

+0

Doh! 빠른 답변 감사합니다! – hernamesbarbara