Note that there are some explanatory texts on larger screens.

plurals
  1. POpandas Timedelta error
    primarykey
    data
    text
    <p>I'm getting errors when running the code samples from the pandas documentation. </p> <p>I suspect it might be related to the version of pandas I'm using, but I haven't been able to confirm that. </p> <pre><code>pandas VERSION 0.10.1 numpy VERSION 1.7.0 scipy VERSION 0.12.0.dev-14b1e07 </code></pre> <p>The below examples are taken directly from the pandas documentation here: </p> <p><a href="http://pandas.pydata.org/pandas-docs/dev/timeseries.html#time-deltas" rel="nofollow">pandas - Time Deltas</a><br> This works </p> <pre><code>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 </code></pre> <p>as does this </p> <pre><code>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 </code></pre> <p>This seems to be consistent with the expected output according to the documentation. </p> <p>The next line in the sample code yields an error: </p> <pre><code>df['C'] = df['A'] + df['B'] </code></pre> <p>... </p> <pre><code>--------------------------------------------------------------------------- TypeError Traceback (most recent call last) &lt;ipython-input-55-7057e174d79e&gt; in &lt;module&gt;() ----&gt; 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) ---&gt; 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) &amp; notnull(y) ---&gt; 65 result[mask] = op(x[mask], y[mask]) 66 else: 67 mask = notnull(x) TypeError: ufunc add cannot use operands with types dtype('&lt;M8[ns]') and dtype('O') </code></pre> <p>Datatypes: </p> <pre><code>df.dtypes Out[56]: A datetime64[ns] B object </code></pre> <p>Similarly, I get an error when I do addition/subtraction:</p> <pre><code>s - s.max() &lt;ipython-input-57-8d53e24db927&gt; in &lt;module&gt;() ----&gt; 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 ---&gt; 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: -&gt; 1005 tipo = arr_or_dtype.dtype.type 1006 return issubclass(tipo, np.datetime64) 1007 AttributeError: 'Timestamp' object has no attribute 'dtype' </code></pre> <p>This code is in a gist for easy reference. </p> <p><a href="https://gist.github.com/hernamesbarbara/5061972" rel="nofollow">https://gist.github.com/hernamesbarbara/5061972</a></p> <p>Thanks for any help or suggestions; it is much appreciated.</p> <p>-Austin</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload