Skip to content
Advertisement

Find timedelta hour with highest number of occurences in pandas dataframe

I have a dataframe where I store orders and the time at which they are received

JavaScript

There are may orders but the dataframe contains orders for the month. I want to know which hour I receive the most orders during the month. I tried creating a series like this.

JavaScript

So that I could group by hour like this

JavaScript

But it doesn’t make sense because I want to get the hour where I receive the most orders. How would I achieve this?

Advertisement

Answer

I want to get the hour where I receive the most orders

Here is nice use Series.value_counts, because by default sorting by counts.

JavaScript

So for top hour select first index value:

JavaScript

And for top value select first value of Series:

JavaScript
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement