I have a JSON file full of unix timestamps in string form. I am trying to convert these timestamps to human readable times to then display in matplotlib.pyplot.
Upon converting the timestamps I am getting the error:
ValueError: unconverted data remains: .1806107
How can I convert my dates to a human readable form YY-MM-DD HH-MM-SS
?
contents = json.loads(open("foo.json").read())
dates = [ ticker['date'] for ticker in contents ]
data = [ ticker['last'] for ticker in contents ]
# Example of array contents
#dates = [1497918349.3060017, 1497918352.9935713, 1497918358.8218484, 1497918364.0406654, 1497918368.9628277]
#data = [1,2,3,4,5]
# Error occurs here
dates=[dt.datetime.strptime(str(date),'%Y%m%d%H%M') for date in dates]
# Also tried the following but I get the error:
# TypeError: an integer is required (got type datetime.datetime)
dates=[dt.datetime.fromtimestamp(date) for date in dates]
plt.plot(dates, data, 'r-')
plt.show()