code: def _add_group_columns(data, gdf):
      
      n = len(data)
      if isinstance(gdf, GroupedDataFrame):
          for i, col in enumerate(gdf.plydata_groups):
              if col not in data:
                  group_values = [gdf[col].iloc[0]] * n
                  # Need to be careful and maintain the dtypes
                  # of the group columns
                  if pdtypes.is_categorical_dtype(gdf[col]):
                      col_values = pd.Categorical(
                          group_values,
                          categories=gdf[col].cat.categories,
                          ordered=gdf[col].cat.ordered
                      )
                  else:
                      col_values = pd.Series(
                          group_values,
                          index=data.index,
                          dtype=gdf[col].dtype
                      )
                  # Group columns come first
                  data.insert(i, col, col_values)
      return data
docs: Add group columns to data with a value from the grouped dataframe
  
      It is assumed that the grouped dataframe contains a single group
  
      >>> data = pd.DataFrame({
      ...     'x': [5, 6, 7]})
      >>> gdf = GroupedDataFrame({
      ...     'g': list('aaa'),
      ...     'x': range(3)}, groups=['g'])
      >>> _add_group_columns(data, gdf)
         g  x
      0  a  5
      1  a  6
      2  a  7