def almost_equal(f: DataFrame, g: DataFrame) -> bool:
    if f.empty or g.empty:
        return f.equals(g)
    else:
        F = (
            f.sort_index(axis=1)
            .sort_values(list(f.columns))
            .reset_index(drop=True)
        )
        G = (
            g.sort_index(axis=1)
            .sort_values(list(g.columns))
            .reset_index(drop=True)
        )
        return F.equals(G)