I am trying to return the index of DataFrame statement, first I am loading a csv (CSV example below)
I created a code to count the number of each hour and return the max number as below
import pandas as pd filename = 'mylist.csv' df = pd.read_csv(filename) df['Start Time'] = df['Start Time'].astype('datetime64[ns]') df['hour'] = df['Start Time'].dt.hour # find the most common hour (from 0 to 23) popular_hour = df.groupby(['hour'])['hour'].count().max() print('Most Frequent Start Hour:', popular_hour) what I am trying to do is to return the hour not the counted value, I've tried index as below but doesn't work
popular_hour = df.groupby(['hour'])['hour'].count().max().index.values 