AttributeError: 'Timestamp' object has no attribute 'timestamp
<p>While converting a <code>panda</code> object to a timestamp, I am facing this strange issue.</p>

<p>Train['date'] value is like <code>01/05/2014</code> which I am trying to convert into linuxtimestamp.</p>

<p>My code:</p>

<pre><code>Train = pd.read_csv("data.tsv", sep='\t') # use TAB as column separator
Train['timestamp'] = pd.to_datetime(Train['date']).apply(lambda a: a.timestamp())
</code></pre>

<p>And I get this error:</p>

<pre><code>Traceback (most recent call last):
  File "socratis.py", line 11, in &lt;module&gt;
    Train['timestamp'] = pd.to_datetime(Train['date']).apply(lambda a: a.timestamp())
  File "/home/ubuntu/.local/lib/python2.7/site-packages/pandas/core/series.py", line 2220, in apply
    mapped = lib.map_infer(values, f, convert=convert_dtype)
  File "pandas/src/inference.pyx", line 1088, in pandas.lib.map_infer (pandas/lib.c:62658)
  File "socratis.py", line 11, in &lt;lambda&gt;
    Train['timestamp'] = pd.to_datetime(Train['date']).apply(lambda a: a.timestamp())
AttributeError: 'Timestamp' object has no attribute 'timestamp'
</code></pre>

<p>You're looking for <a href="https://docs.python.org/3/library/datetime.html#datetime.datetime.timestamp" rel="nofollow"><code>datetime.timestamp()</code></a>, which was added in Python 3.3. Pandas itself isn't involved.</p>

<blockquote>
  <p><em>N.B.</em> <code>.timestamp()</code> will localize naive timestamps to the computer's UTC offset. To the contrary, suggestions in this answer are timezone-agnostic.</p>
</blockquote>

<p>Since pandas <a href="http://pandas.pydata.org/pandas-docs/stable/timeseries.html#timestamp-limitations" rel="nofollow">uses nanoseconds internally</a> (numpy <a href="http://docs.scipy.org/doc/numpy/reference/arrays.datetime.html#datetime-units" rel="nofollow">datetime64[ns]</a>), you should be able to do this even with Python 2:</p>

<pre><code>Train['timestamp'] = pd.to_datetime(Train['date']).value / 1e9
</code></pre>

<p>Or be more explicit wtih something like this (from the datetime docs):</p>

<pre><code>import pandas as pd
from datetime import datetime, timedelta

def posix_time(dt):
    return (dt - datetime(1970, 1, 1)) / timedelta(seconds=1)

Train['timestamp'] = pd.to_datetime(Train['date']).apply(posix_time)
</code></pre>

python time timestamp