def find_schedule():
    top_stations = pd.read_csv('df_top.csv')
    top_stations.rename(columns={'name': 'STATION'}, inplace=True)
    top_stations1 = top_stations.loc[:, ['STATION', 'toucan_score']]
    turnstile_data = t.read_mta_turnstile(start='20180501', end='20180531')
    turnstile_data1 = turnstile_data.loc[:, ['STATION', 'DATE', 'TIME', 'hourly_entries', 'hourly_exits']]
    turnstile_data2 = turnstile_data1.merge(top_stations1, on='STATION')
    schedule = pd.DataFrame(columns=['STATION', 'hour_of_day', 'day_name', 'hourly_entries'])
    agg = turnstile_data1.groupby(['STATION', 'DATE', 'TIME'])[['hourly_entries']].sum().reset_index()
    agg.DATE = pd.to_datetime(agg.DATE, format='%m/%d/%Y')
    agg.TIME = pd.to_datetime(agg.TIME, format='%H:%M:%S')
    agg['day_name'] = agg.DATE.dt.day_name()
    agg['hour_of_day'] = agg.TIME.dt.hour
    agg = agg[((agg['hour_of_day'] > 5) & (agg['hour_of_day'] < 19))]
    l_times = []
    for h in agg.hour_of_day:
        if (int(h) <= 11):
            l_times.append('Morning')
        elif (int(h) >= 15):
            l_times.append('Evening')
        else:
            l_times.append('Afternoon')
    agg.hour_of_day = l_times
    for station_name in top_stations1.STATION.unique():
        hm = agg.loc[((agg.STATION == station_name), ['hour_of_day', 'day_name', 'hourly_entries'])]
        hm = hm.groupby(['hour_of_day', 'day_name'])['hourly_entries'].mean().reset_index()
        hm = hm.pivot(index='hour_of_day', columns='day_name', values='hourly_entries')
        sc = hm.stack().nlargest(3).reset_index()
        sc.rename(columns={0: 'hourly_entries'}, inplace=True)
        sc['STATION'] = ([station_name] * 3)
        schedule = schedule.append(sc)
    schedule['p'] = ([1] * schedule.shape[0])
    schedule_pivot = schedule.pivot_table(index=['STATION'], columns=['day_name', 'hour_of_day'], values='p')
    return schedule_pivot
def find_schedule():
    top_stations = pd.read_csv('df_top.csv')
    top_stations.rename(columns={'name': 'STATION'}, inplace=True)
    top_stations1 = top_stations.loc[:, ['STATION', 'toucan_score']]
    turnstile_data = t.read_mta_turnstile(start='20180501', end='20180531')
    turnstile_data1 = turnstile_data.loc[:, ['STATION', 'DATE', 'TIME', 'hourly_entries', 'hourly_exits']]
    turnstile_data2 = turnstile_data1.merge(top_stations1, on='STATION')
    schedule = pd.DataFrame(columns=['STATION', 'hour_of_day', 'day_name', 'hourly_entries'])
    agg = turnstile_data1.groupby(['STATION', 'DATE', 'TIME'])[['hourly_entries']].sum().reset_index()
    agg.DATE = pd.to_datetime(agg.DATE, format='%m/%d/%Y')
    agg.TIME = pd.to_datetime(agg.TIME, format='%H:%M:%S')
    agg['day_name'] = agg.DATE.dt.day_name()
    agg['hour_of_day'] = agg.TIME.dt.hour
    agg = agg[((agg['hour_of_day'] > 5) & (agg['hour_of_day'] < 19))]
    l_times = []
    for h in agg.hour_of_day:
        if (int(h) <= 11):
            l_times.append('Morning')
        elif (int(h) >= 15):
            l_times.append('Evening')
        else:
            l_times.append('Afternoon')
    agg.hour_of_day = l_times
    for station_name in top_stations1.STATION.unique():
        hm = agg.loc[((agg.STATION == station_name), ['hour_of_day', 'day_name', 'hourly_entries'])]
        hm = hm.groupby(['hour_of_day', 'day_name'])['hourly_entries'].mean().reset_index()
        hm = hm.pivot(index='hour_of_day', columns='day_name', values='hourly_entries')
        sc = hm.stack().nlargest(3).reset_index()
        sc.rename(columns={0: 'hourly_entries'}, inplace=True)
        sc['STATION'] = ([station_name] * 3)
        schedule = schedule.append(sc)
    schedule['p'] = ([1] * schedule.shape[0])
    schedule_pivot = schedule.pivot_table(index=['STATION'], columns=['day_name', 'hour_of_day'], values='p')
    return schedule_pivot