I am struggling to get my code running. There seems to be a problem with the timestamp. Do you have any suggestions to how I could change my code? I saw that this had been asked before, but did not manage to make it work.
This is the error I get when running the code: 'Timestamp' object has no attribute 'timestamp'
My code:
import quandl, math, datetime
last_date = df.iloc[-1].name
last_unix = last_date.timestamp()
one_day = 86400 #Seconds in a day
next_unix = last_unix + one_day
for i in forecast_set:
next_date = datetime.datetime.fromtimestamp(next_unix)
next_unix += one_day
df.loc[next_date]=[np.nan for _ in range(len(df.columns)-1)]+[i]
#Loop to replace all numbers on x axis with dates
You can try this:
import time
.....
last_unix = time.mktime(last_date.timetuple())
That worked for me!
I had the same problem but with Python 3.4 and I used the following solution.
last_unix = (last_date - datetime.datetime(1970,1,1)).total_seconds()
I've had the same problem. I've needed to provide an access to timestamp
in both: python2 and python3 environments (timestamps
wasn't the main purpose of my module).
After several attempts to provide compatibility, I have installed arrow
package. It is already tested, pypi-published, and it works on many version of Python.
Install from PyPI
pip install arrow
Or add to dependencies
import arrow
import quandl, math, datetime
last_date = df.iloc[-1].name
# use arrow
last_unix = arrow.get(last_date).timestamp
one_day = 86400 #Seconds in a day
next_unix = last_unix + one_day
# ... your code ...
Also, there are a lot of nifty and useful features (for example - no more tortures with time zones).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With