'Timestamp' object has no attribute 'timestamp'

11,778

You don't actually ask a question (tip for next time: be more explicit), but I assume you want an epoch / Unix timestamp from a Pandas Timestamp object.

If you use the pandas.tslib.Timestamp.value method, you'll return the timestamp in microseconds (1/1,000,000 second):

In [1]: import pandas as pd

In [2]: date_example = pd.to_datetime("2016-06-21")

In [3]: type(date_example)
Out[3]: pandas.tslib.Timestamp

In [4]: date_example.value
Out[4]: 1466467200000000000

If you prefer you can simply divide by 1000 to get milliseconds or 1000000 to get whole seconds, eg:

In [5]: date_example.value / 1000000
Out[5]: 1466467200000
Share:
11,778
user6162407
Author by

user6162407

Updated on June 04, 2022

Comments

  • user6162407
    user6162407 almost 2 years

    I'm following a course where I have to convert a date to a unix timestamp.

    import pandas as pd
    
    df = pd.read_csv('file.csv')
    print type(df.iloc[-1].name)
    

    class 'pandas.tslib.Timestamp'

    ts = df.iloc[-1].name.timestamp()
    

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