def add_G_rows_gabors(df):
    """
    add_G_rows_gabors(df)

    Returns dataframe with grayscreen (G) rows added between Gabor D/U and 
    Gabor A segments.

    Required args:
        - df (pd DataFrame): gabor stimulus dataframe with columns "gabfr", 
                             "stimSeg", "start2pfr", "end2pfr", "start_stim_fr", 
                             "end_stim_fr", "surp"

    Returns:
        - df (pd DataFrame): gabor stimulus dataframe with grayscreen (G) rows 
                             added
    """

    df = df.copy()

    df = df.sort_values("start2pfr").reset_index(drop=True)

    if "gabfr" not in df.columns:
        raise ValueError("Should only be used with dataframes containing "
                         "gabor frame information")

    # add in lines for grayscreen (G) with parameters of previous segment
    # except gabfr and start/end frames          
    pre_seg = df.loc[(df["gabfr"] == 3)].reset_index(drop=True)
    pre_seg = pre_seg.loc[(pre_seg["stimSeg"] < max(df["stimSeg"]))]

    post_seg = df.loc[(df["gabfr"] == 0)].reset_index(drop=True)
    post_seg = post_seg.loc[(post_seg["stimSeg"] > min(df["stimSeg"]))]

    G_seg = pre_seg.copy()
    G_seg["gabfr"] = "G"

    G_seg["start2pfr"]     = pre_seg["end2pfr"].values
    G_seg["start_stim_fr"] = pre_seg["end_stim_fr"].values
    G_seg["end2pfr"]       = post_seg["start2pfr"].values
    G_seg["end_stim_fr"]   = post_seg["start_stim_fr"].values

    df = df.append(G_seg).sort_values("start2pfr").reset_index(drop=True)

    df["surp"] = df["surp"].astype(int)
    
    return df