def get_trips_grouped(trips, tours):
    """Helper function to get grouped trips by tour id

    Parameters
    ----------
    trips: GeoDataFrame (as trackintel trips)
        Trips dataframe

    tours: GeoDataFrame (as trackintel tours)
        Output of generate_tours function, must contain column "trips" with list of trip ids on tour


    Returns
    -------
    trips_grouped_by_tour: DataFrameGroupBy object
        Trips grouped by tour id

    Notes
    -------
    This function is necessary because when running generate_tours, one trip only gets the tour ID of the smallest
    tour it belongs to assigned. Here, we return all trips for each tour, which might contain a nested tour.
    """
    trips_inp = trips.copy()
    if "tour_id" in trips_inp.columns:
        trips_inp.drop(columns=["tour_id"], inplace=True)
    # make smaller version of tours
    tours_to_trips = tours.reset_index()[["id", "trips"]]
    # switch to trips id as index
    tours_to_trips.rename(columns={"id": "tour_id", "trips": "trip_id"}, inplace=True)
    # expand this small version so that each trip id is one row
    tours_expanded = tours_to_trips.explode("trip_id").reset_index(drop=True)

    # join with trips table by id
    tours_with_trips = tours_expanded.merge(trips_inp, left_on="trip_id", right_on="id", how="left")
    # group
    trips_grouped_by_tour = tours_with_trips.groupby("tour_id")
    return trips_grouped_by_tour