Getting back into NumPy, Day 3
Today we’re pushing on with the heat maps. I still don’t have much data to analyze, but as I continue with the 100 day challenge, the data will more or less collect itself.
So far I have a graph showing my distribution over the day, and one graph showing a heat map with the activity since the day I started. Next step is a heat map over the whole year. With this graph I can then see how my activity has changed over the year. And it introduces a small problem that I need to solve.
A day always have the same amount of minutes in it (modulo strange days with leap minutes and leap seconds), but this isn’t the case with months. And if I take the naive route and just try to add the groupings to the dataframe, I get the following error:
ValueError: Length of values does not match length of index Why is this? The columns of my dataframe are 31 days, 28 days, 30 days, and so on long. And just adding them with the same method (dataframe[index]) doesn’t work since it seems that Pandas expects columns of the same length.
Thanks to an answer on StackOverflow, I managed to solve this problem fairly easy, using Pandas concat function.
One small thing also needed some attention. Doing the second grouping in the naive way, using dataframe.index.day, yielded a strange error:
ValueError: Grouper and axis must be same length I’m still not quite sure why this error showed up, but the solution was simple. Do the sorting with a lambda instead, and reference the day-property of the anonymous variable.
And of course, just as yesterday, I need to extend the data frame with zeros so that there is data available for a full year.
All in all: here’s the full code for this heat map.
This yields the following beautiful picture with mostly zero values. But it’s good to know it will fill itself over the year :-)
As a note: I’m using the colormap “Cividis” since the colormap “Hot” made the days with the highest entries indistinguishable from days without entry (both turn out white), and I’m transposing the matrix to make the graph lengthy instead of tall. Everything for readability and beauty!