0

I have a dateframe with, for every hour for each day, the amount of gas and electricity used:

                            elec    gas day_of_week DuringBusinessHours
ts              
2022-04-30 01:00:00+02:00   3.6000000834465027  0.0 5   False
2022-04-30 02:00:00+02:00   3.6000000834465027  0.0 5   False
2022-04-30 03:00:00+02:00   3.6000000834465027  0.0 5   False
2022-04-30 04:00:00+02:00   3.6000000834465027  0.0 5   False
2022-04-30 05:00:00+02:00   4.0000001192092896  0.0 5   False
2022-04-30 06:00:00+02:00   3.6000000834465027  0.0 5   False
2022-04-30 07:00:00+02:00   3.200000047683716   0.0 5   False
2022-04-30 08:00:00+02:00   3.200000047683716   0.0 5   False
2022-04-30 09:00:00+02:00   3.6000000834465027  0.0 5   False
2022-04-30 10:00:00+02:00   3.200000047683716   0.3000000119209289  5   False
2022-04-30 11:00:00+02:00   3.200000047683716   0.0 5   False
2022-04-30 12:00:00+02:00   3.6000000834465027  0.0 5   False
2022-04-30 13:00:00+02:00   3.200000047683716   0.0 5   False
2022-04-30 14:00:00+02:00   3.200000047683716   0.0 5   False
2022-04-30 15:00:00+02:00   3.200000047683716   0.0 5   False
2022-04-30 16:00:00+02:00   3.6000000834465027  0.0 5   False
2022-04-30 17:00:00+02:00   3.200000047683716   0.0 5   False
2022-04-30 18:00:00+02:00   3.6000000834465027  0.0 5   False
2022-04-30 19:00:00+02:00   3.6000000834465027  0.0 5   False
2022-04-30 20:00:00+02:00   3.200000077486038   0.0 5   False
2022-04-30 21:00:00+02:00   3.200000047683716   0.0 5   False
2022-04-30 22:00:00+02:00   3.200000047683716   0.0 5   False
2022-04-30 23:00:00+02:00   3.6000000834465027  0.0 5   False
2022-05-01 00:00:00+02:00   3.199999988079071   0.0 6   False
2022-05-01 01:00:00+02:00   3.200000047683716   0.0 6   False
2022-05-01 02:00:00+02:00   3.200000047683716   0.0 6   False
2022-05-01 03:00:00+02:00   3.6000000834465027  0.0 6   False
2022-05-01 04:00:00+02:00   3.6000000834465027  1.2000000476837158  6   False
2022-05-01 05:00:00+02:00   3.6000000834465027  0.4000000059604645  6   False
2022-05-01 06:00:00+02:00   3.6000000834465027  0.6000000238418579  6   False

For each week, I would like to get the lowest electricity value and display it in a new dataframe with the corresponding hour and day. But so far for each method I have used, it does not come up with the right minimum value. For example:

lowestUsage = BusinessUsageDf.groupby([pd.Grouper(level='ts', freq='W-SAT')])['elec'].min()
lowestUsage.head(5)

Gives:

ts
2022-04-23 00:00:00+02:00     3.200000047683716
2022-04-30 00:00:00+02:00     10.00000023841858
2022-05-07 00:00:00+02:00    10.400000095367432
2022-05-14 00:00:00+02:00     10.00000011920929
2022-05-21 00:00:00+02:00     10.00000023841858
Freq: W-SAT, Name: elektra, dtype: object

But the lowest value of the week between 04-30 and 05-07 is not 10.400.. because according to the data, this should be 3.100.. I also tried:

lowestUsageWeekDf = BusinessUsageDf.resample("W").min()

But this is neither giving the correct minimum value. What is going on in here?

1 Answer 1

0

Try:

lowestUsage = BusinessUsageDf.groupby(pd.Grouper(key='ts', freq='W-SAT'))['elec'].min()
lowestUsage.head(5)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.