def gen_num_replies(df):
    """
    Generate feature with number of posts by user which were replies to other users (i.e., not to themselves, and not first post in thread).
    :param df: pd.DataFrame of forum post data.
    :return: pd.DataFrame of 'session_user_id', 'week', and num_replies.
    """
    df.sort_values(by=['thread_id', 'post_time'], inplace=True)
    df['previous_post_user_id'] = df.groupby('thread_id')['session_user_id'].shift()
    df_reply = df[(df.thread_order != 1) & (df.session_user_id != df.previous_post_user_id)]
    df_out = df_reply.groupby(['session_user_id', 'week']).size().rename('num_replies').reset_index()
    return df_out