I have a csv file that contains a table shown by the example below:
| TimeStampHour | Day | Hour | Count |
|------------------|-----|------|-------|
| 28/01/2019 00:00 | Mon | 0 | 198 |
| 28/01/2019 01:00 | Mon | 1 | 513 |
| 28/01/2019 02:00 | Mon | 2 | 110 |
| 28/01/2019 03:00 | Mon | 3 | 50 |
| 28/01/2019 04:00 | Mon | 4 | 6 |
| 28/01/2019 05:00 | Mon | 5 | 6 |
| 28/01/2019 06:00 | Mon | 6 | 1503 |
| 28/01/2019 07:00 | Mon | 7 | 108 |
| 28/01/2019 08:00 | Mon | 8 | 211 |
| 28/01/2019 09:00 | Mon | 9 | 169 |
...
There are further values that go on for several months and contain the other days of the week all the way till Sunday.
What I am trying to achieve:
I want to first find the 25 smallest rows by the count and then output those rows. I have done the following to achieve this in python:
import pandas as pd
import numpy as np
df = pd.read_csv('mydata.csv')
least25 = df.nsmallest(25, "Count",keep='all')
print(least25)
OUTPUT:
TimeStampHour Day Hour Count
124 02/02/2019 07:00 Sat 7 3
142 03/02/2019 04:00 Sun 4 3
143 03/02/2019 06:00 Sun 6 3
144 03/02/2019 07:00 Sun 7 3
165 04/02/2019 04:00 Mon 4 3
... ... ... ... ...
1940 20/04/2019 04:00 Sat 4 6
1965 21/04/2019 05:00 Sun 5 6
2131 28/04/2019 04:00 Sun 4 6
3138 09/06/2019 03:00 Sun 3 6
4144 21/07/2019 03:00 Sun 3 6
This I am happy with.
My next step is to perform a mode calculation on these results so that I can output the rows where the modes exist in the same output format as above (showing rows and colums).
My desired output would look like this:
| Day | Hour | Count(Min) | Occurance |
|-----|------|------------|-----------|
| Wed | 6 | 3 | 10 |
| Wed | 7 | 3 | 8 |
| Wed | 8 | 3 | 7 |
| Wed | 9 | 3 | 9 |
| Wed | 10 | 3 | 11 |
| Wed | 11 | 3 | 7 |
| Wed | 12 | 3 | 5 |
| Fri | 7 | 3 | 1 |
| Fri | 8 | 3 | 6 |
| Fri | 9 | 3 | 7 |
In other words: Print the rows with the most common miniumum (the modal minimum) the most frequent occurring minimum count. In order to try and achieve this is did the following:
modeOfmin = least25['Count'].mode()
print(modeOfMin)
OUTPUT:
0 6
dtype: int64
I would like to learn how to achieve my desired output but I do not know how to go about this.
Would someone be able to explain this?