class_docstr: Generates a gridded Dataset of 2D aggregate arrays indexed by the
  first two dimensions of the passed Element, turning all remaining
  dimensions into value dimensions. The key dimensions of the
  gridded array are treated as categorical indices. Useful for data
  indexed by two independent categorical variables such as a table
  of population values indexed by country and year. Data that is
  indexed by continuous dimensions should be binned before
  aggregation. The aggregation will retain the global sorting order
  of both dimensions.
  
  >> table = Table([('USA', 2000, 282.2), ('UK', 2005, 58.89)],
                   kdims=['Country', 'Year'], vdims=['Population'])
  >> categorical_aggregate2d(table)
  Dataset({'Country': ['USA', 'UK'], 'Year': [2000, 2005],
           'Population': [[ 282.2 , np.nan], [np.nan,   58.89]]},
          kdims=['Country', 'Year'], vdims=['Population'])
class_docstr_tok: ["Generates","a","gridded","Dataset","of","2D","aggregate","arrays","indexed","by","the","first","two","dimensions","of","the","passed","Element",",","turning","all","remaining","dimensions","into","value","dimensions",".","The","key","dimensions","of","the","gridded","array","are","treated","as","categorical","indices",".","Useful","for","data","indexed","by","two","independent","categorical","variables","such","as","a","table","of","population","values","indexed","by","country","and","year",".","Data","that","is","indexed","by","continuous","dimensions","should","be","binned","before","aggregation",".","The","aggregation","will","retain","the","global","sorting","order","of","both","dimensions",".",">",">","table","=","Table","(","[","(","'USA","'",",","2000",",","282.2",")",",","(","'UK","'",",","2005",",","58.89",")","]",",","kdims=","[","'Country","'",",","'Year","'","]",",","vdims=","[","'Population","'","]",")",">",">","categorical_aggregate2d","(","table",")","Dataset","(","{","'Country","'",":","[","'USA","'",",","'UK","'","]",",","'Year","'",":","[","2000",",","2005","]",",","'Population","'",":","[","[","282.2",",","np.nan","]",",","[","np.nan",",","58.89","]","]","}",",","kdims=","[","'Country","'",",","'Year","'","]",",","vdims=","[","'Population","'","]",")"]
code: def _aggregate_dataset_pandas(self, obj):
      index_cols = [d.name for d in obj.kdims]
      df = (
          obj.data.set_index(index_cols)
          .groupby(index_cols, sort=False)
          .first()
      )
      label = "unique" if len(df) == len(obj) else "non-unique"
      levels = self._get_coords(obj)
      index = pd.MultiIndex.from_product(levels, names=df.index.names)
      reindexed = df.reindex(index)
      data = tuple(levels)
      shape = tuple(d.shape[0] for d in data)
      for vdim in obj.vdims:
          data += (reindexed[vdim.name].values.reshape(shape).T,)
      return obj.clone(data, datatype=self.p.datatype, label=label)
  
imports: import itertools
  import numpy
  import pandas
  import param
  from ..core import Dataset
  from ..core.boundingregion import BoundingBox
  from ..core.data import PandasInterface, default_datatype
  from ..core.operation import Operation
  from ..core.sheetcoords import Slice
  from ..core.util import cartesian_product, datetime_types, is_cyclic, is_nan, one_to_one, sort_topologically
label_desc: Use image node_id 3 for calling the categorical_aggregate2d obj's underlying member method code with example usage: obj._aggregate_dataset_pandas(obj) and returns: obj