Wouter
Wouter

Reputation: 487

How to divide 24 hours into 96 quarters?

I'm trying to come up with some logic to cleanly divide 24 hours into 96 quarters but I can't figure it out. I have a Python Pandas dataframe showing the hours and quarters of each time stamp. It looks like this

Timestamp              | Hour |  Quarter
----------------------------------------
2020-11-01 05:00:00+01    5        1
2020-11-01 05:15:00+01    5        2
2020-11-01 05:30:00+01    5        3
2020-11-01 05:45:00+01    5        4
2020-11-01 06:00:00+01    6        1
2020-11-01 06:15:00+01    6        2
2020-11-01 06:30:00+01    6        3
2020-11-01 06:45:00+01    6        4

So here it shows the quarters for each hour (every hour has 4 quarters). But now I want to have 96 quarters for the entire day. So I would add a column:

Timestamp              | Hour |  Quarter  | Q's
------------------------------------------------
2020-11-01 05:00:00+01    5        1         21
2020-11-01 05:15:00+01    5        2         22
2020-11-01 05:30:00+01    5        3         23
2020-11-01 05:45:00+01    5        4         24
2020-11-01 06:00:00+01    6        1         25
2020-11-01 06:15:00+01    6        2         26
2020-11-01 06:30:00+01    6        3         27
2020-11-01 06:45:00+01    6        4         28

Because I'm working with timestamps which are timezone sensitive, I can't just do this index wise. Also I don't like for loops. What's the logic here that I am completely missing?

Upvotes: 0

Views: 365

Answers (1)

Thomas
Thomas

Reputation: 182000

Isn't it simply this?

df["Q's"] = 4 * df["Hour"] + df["Quarter"]

Upvotes: 3

Related Questions