0

I am formatting the original timestamps in my MongoDB documents. The original ones look like this:

"timestamp" : ISODate("2013-03-06T17:10:29Z")

And the formatted ones (Used as _id of the documents after using aggregation):

"_id" : "06-03-13T17:10"

I then want to plot the "amount" (y axis) values against the "_id" values (x axis)

I am having trouble formatting the _id so that I can plot it.

amount = [book["price"] for book in sorted["result"]]
time = [book["_id"] for book in sorted["result"]]
P.plot(amount, time)
P.show()

Returns:

ValueError: invalid literal for float(): 06-03-13T15:36
Julia
  • 1,369
  • 4
  • 18
  • 38

1 Answers1

1

You're passing the plot function a string, which is not a valid x-axis format as far as I know. I'm pretty sure you want to have your original datetime objects, and then use date2num to format them to pass to matplotlib. So depending on if you're using the strftime formatted stuff for anything else, it might make more sense to store the output of date2num in your mapping, rather than the output of strftime.

See this post for a little more specificity and links to some examples.

Community
  • 1
  • 1
Henry Keiter
  • 16,863
  • 7
  • 51
  • 80
  • thanks, but how would i manage to remove the seconds in my datetime objects? – Julia Mar 11 '13 at 15:47
  • @Julia do you need to remove the seconds from the datetimes, or just from the format string? You should be able to give matplotlib a `strftime` format string to use. If you need to strip seconds from your datetimes, that's just `dt = dt.replace(second=0)`. – Henry Keiter Mar 11 '13 at 15:58