Anonymous Anonymous - 2 months ago
167 1

asdf

Python

Plot the average speed of all recorded buses within t minute intervals

import datetime

def plot_avg_spd(df, t):
    """ Plot the average speed of all recorded buses within t minute intervals 
    Args: 
        df (pd.DataFrame): dataframe of bus data
        t (int): the granularity of each time period (in minutes) for which an average is speed is calculated
    """
    def modIt(a):
        return (a - pd.Timedelta(minutes=(a.minute % t))).time()

    df['tmstmp'] = df['tmstmp'].apply(modIt)

    groups = df.groupby(['tmstmp'])
    y = []
    x = []
    for key, group in groups:
        a = group['spd'].mean()
        
        y.append(a)
        x.append(key)
        
    area = np.pi * 10
#     e = 

    return plt.scatter(x,y)
    pass