[Solved] Sorting Pandas data by hour of the day


after converting to datetime pd.to_datetime(df['date']) you can create a separate column with the hour in it, e.g. df['Hour'] = df.date.dt.hour and then sort by it
df.sort_values('Hour')

EDIT:

As you want to sort by time you can instead of using hour, put the timestamp part into a ‘time’ column. In order to get times between 9 and 10 you can filter by where hour==9 and then sort by the time column as per below

df['date'] = pd.to_datetime(df['date'])

#put the timestamp part of the datetime into a separate column
df['time'] = df['date'].dt.time

#filter by times between 9 and 10 and sort by timestamp
df.loc[df.date.dt.hour==9].sort_values('time')

7

solved Sorting Pandas data by hour of the day