Here's a riddle. I'm working with a Pandas dataframe in Python which has an index based on minutes, from 6 AM to 1 AM. There are multiple columns, holding values related to a specific minute. It looks something like this:
Timebands | Column A | Column B |
---|---|---|
06:00 | 1 | 2 |
06:01 | 0.5 | 3 |
06:02 | 2 | 0.5 |
06:03 | 0.7 | 1.2 |
.......... | ............ | ........... |
24:59 | 0.3 | 1 |
I need the averages of 15 minute intervals, i.e. from 06:00 to 06:14, 06:15 to 06:29, etc., which I'll then use in tables and charts. The intervals go all the way to 1 AM, but it has specific intervals inside the whole day table as well. For example, it can be a 3-hour interval, from 6 AM to 8 AM, from 9 AM to 11 AM, etc. But here's the catch: this table is day-sensitive, so the 3 hour intervals are different depending on whether the day is Monday through Thursday, or Friday, or Saturday, or Sunday. Four day-intervals.
So hard-coding this is possible, but there has to be a better way. Because even the interval varies. Depending on the day, it might be 1 hour long, and not 3. All the intervals are hard-coded into json (basically, these are TV ratings, and the intervals are specific shows, which change from day to day).
What I want is to connect all the shows from the json files, which say "this show starts at 9 AM and ends at 11 AM", with the rating file, and get averages of every 15 minutes this show is on. Four intervals per hour for the whole slot I specify.
What is a good way of defining a class/function that gets me the averages of four 15min intervals per hour, which is callable depending on the whole interval I need? I hope this all makes sense, I've been racking my brain for the past 2 days with this, I'm spent.
Tried hard-coding, but it's a bad solution. I'm imagining something like x for range(x, x+15) where I set the minute as start, but this becomes a problem as it would be loc + iloc at the same time. Loc for the "16:00" hour, for example, iloc for the next 14 elements after '16:00'.