def join_event_dfs(event_df, behavioral_df):
    """Join a behavioral and an event dataframe."""
    
    # sort both dataframes after trial, subject, tap
    event_df = event_df.sort_values(['event_trial', 'event_name'])
    behavioral_df = behavioral_df.sort_values(['trial', 'subject', 'tapnr'])
    
    # reset the event df index to the behavioral df
    event_df.index = behavioral_df.index
    
    return event_df.join(behavioral_df).drop(columns=['event_trial'])