def gen_thread_order(df):
    """
    Add column with order of post within each thread, by timestamp.
    :param df: pd.DataFrame of forum post data.
    :return: pd.DataFrame of forum data with thread_order column.
    """
    df.sort_values(by = ['thread_id', 'post_time'], inplace = True)
    df['thread_order'] = df.groupby(['thread_id'])['thread_id'].rank(method='first')
    return df