Question:I’m trying to generate a frequency DataFrame in Jupyter/Python of HH:MM:SS elements of a datetime column.
Asside from itterating through all HH:MM:SS combinations and counting them (I need to include 0 values), is there a function in Python that can do it for me?
.value_counts() creates what I need, however, 0 values are not included.
Many thanks, in advance, for your assistance 🙂
Expected to generate a dataframe containing:
Answer:Here’s a solution:
timesbased on the original data (assuming you don’t even have a
Datecolumn, but if you do, you can of course use those) –
timestakes all the times from
dfand then groups and counts them.
However, that is missing the times which don’t occur in
time_countsis constructed by generated all possible times and either selecting the count from
timesor 0 if it doesn’t exist in
category. Perhaps someone has additional suggestions to make that work.
If you have better answer, please add a comment about this, thank you!