Wednesday, 10 November 2021

How can I visualize a series of timestamps with Pandas?

I have a CSV which was generated with this script which looks like this:

date,last_activity
2021-11-03 07:39:14,160
2021-11-03 07:39:44,1594
2021-11-03 07:57:15,4270
2021-11-03 07:57:45,23201
2021-11-03 07:58:15,7
2021-11-03 07:58:45,1015
2021-11-03 07:59:15,2
2021-11-03 07:59:45,3496
2021-11-03 08:28:16,6093
2021-11-03 08:28:46,5513
2021-11-03 08:31:46,16639

I would like to visualize those timestamps as an "activity bar", e.g. like this:

enter image description here

Hence:

  • The x-axis should show the time / the date
  • I want to be able to add a title over it
  • The red stripes indicate when there is a date timestamp.

To make it simpler, the last_activity could be ignored.

The simplest solution I can imagine would be to use one pixel per minute of the day. I can round 2021-11-03 07:39:14 to 2021-11-03 07:39 and just say "I've seen a timestamp for 7:39 -> color that pixel". However, I would only know how to do this directly with matplotlib (pixel-by-pixel). Is there a simpler way with Pandas?



from How can I visualize a series of timestamps with Pandas?

No comments:

Post a Comment