class_docstr: Container for inference data storage using xarray.
  
  For a detailed introduction to ``InferenceData`` objects and their usage, see
  :ref:`xarray_for_arviz`. This page provides help and documentation
  on ``InferenceData`` methods and their low level implementation.
class_docstr_tok: ["Container","for","inference","data","storage","using","xarray",".","For","a","detailed","introduction","to","``","InferenceData","``","objects","and","their","usage",",","see",":","ref",":","`","xarray_for_arviz","`",".","This","page","provides","help","and","documentation","on","``","InferenceData","``","methods","and","their","low","level","implementation","."]
docstr: Convert InferenceData to a :class:`pandas.DataFrame` following xarray naming conventions.
  
  This returns dataframe in a "wide" -format, where each item in ndimensional array is
  unpacked. To access "tidy" -format, use xarray functionality found for each dataset.
  
  In case of a multiple groups, function adds a group identification to the var name.
  
  Data groups ("observed_data", "constant_data", "predictions_constant_data") are
  skipped implicitly.
  
  Raises TypeError if no valid groups are found.
  Raises ValueError if no data are selected.
  
  Parameters
  ----------
  groups: str or list of str, optional
      Groups where the transformation is to be applied. Can either be group names
      or metagroup names.
  filter_groups: {None, "like", "regex"}, optional, default=None
      If `None` (default), interpret groups as the real group or metagroup names.
      If "like", interpret groups as substrings of the real group or metagroup names.
      If "regex", interpret groups as regular expressions on the real group or
      metagroup names. A la `pandas.filter`.
  var_names : str or list of str, optional
      Variables to be extracted. Prefix the variables by `~` when you want to exclude them.
  filter_vars: {None, "like", "regex"}, optional
      If `None` (default), interpret var_names as the real variables names. If "like",
      interpret var_names as substrings of the real variables names. If "regex",
      interpret var_names as regular expressions on the real variables names. A la
      `pandas.filter`.
      Like with plotting, sometimes it's easier to subset saying what to exclude
      instead of what to include
  include_coords: bool
      Add coordinate values to column name (tuple).
  include_index: bool
      Add index information for multidimensional arrays.
  index_origin: {0, 1}, optional
      Starting index  for multidimensional objects. 0- or 1-based.
      Defaults to rcParams["data.index_origin"].
  
  Returns
  -------
  pandas.DataFrame
      A pandas DataFrame containing all selected groups of InferenceData object.
docstr_tok: ["Convert","InferenceData","to","a",":","class",":","`","pandas.DataFrame","`","following","xarray","naming","conventions",".","This","returns","dataframe","in","a","``","wide","''","-format",",","where","each","item","in","ndimensional","array","is","unpacked",".","To","access","``","tidy","''","-format",",","use","xarray","functionality","found","for","each","dataset",".","In","case","of","a","multiple","groups",",","function","adds","a","group","identification","to","the","var","name",".","Data","groups","(","``","observed_data","''",",","``","constant_data","''",",","``","predictions_constant_data","''",")","are","skipped","implicitly",".","Raises","TypeError","if","no","valid","groups","are","found",".","Raises","ValueError","if","no","data","are","selected",".","Parameters","--","--","--","--","--","groups",":","str","or","list","of","str",",","optional","Groups","where","the","transformation","is","to","be","applied",".","Can","either","be","group","names","or","metagroup","names",".","filter_groups",":","{","None",",","``","like","''",",","``","regex","''","}",",","optional",",","default=None","If","`","None","`","(","default",")",",","interpret","groups","as","the","real","group","or","metagroup","names",".","If","``","like","''",",","interpret","groups","as","substrings","of","the","real","group","or","metagroup","names",".","If","``","regex","''",",","interpret","groups","as","regular","expressions","on","the","real","group","or","metagroup","names",".","A","la","`","pandas.filter","`",".","var_names",":","str","or","list","of","str",",","optional","Variables","to","be","extracted",".","Prefix","the","variables","by","`","~","`","when","you","want","to","exclude","them",".","filter_vars",":","{","None",",","``","like","''",",","``","regex","''","}",",","optional","If","`","None","`","(","default",")",",","interpret","var_names","as","the","real","variables","names",".","If","``","like","''",",","interpret","var_names","as","substrings","of","the","real","variables","names",".","If","``","regex","''",",","interpret","var_names","as","regular","expressions","on","the","real","variables","names",".","A","la","`","pandas.filter","`",".","Like","with","plotting",",","sometimes","it","'s","easier","to","subset","saying","what","to","exclude","instead","of","what","to","include","include_coords",":","bool","Add","coordinate","values","to","column","name","(","tuple",")",".","include_index",":","bool","Add","index","information","for","multidimensional","arrays",".","index_origin",":","{","0",",","1","}",",","optional","Starting","index","for","multidimensional","objects",".","0-","or","1-based",".","Defaults","to","rcParams","[","``","data.index_origin","''","]",".","Returns","--","--","--","-","pandas.DataFrame","A","pandas","DataFrame","containing","all","selected","groups","of","InferenceData","object","."]
code: def to_dataframe(
      self,
      groups=None,
      filter_groups=None,
      var_names=None,
      filter_vars=None,
      include_coords=True,
      include_index=True,
      index_origin=None,
  ):
      """Convert InferenceData to a :class:`pandas.DataFrame` following xarray naming conventions.
  
      This returns dataframe in a "wide" -format, where each item in ndimensional array is
      unpacked. To access "tidy" -format, use xarray functionality found for each dataset.
  
      In case of a multiple groups, function adds a group identification to the var name.
  
      Data groups ("observed_data", "constant_data", "predictions_constant_data") are
      skipped implicitly.
  
      Raises TypeError if no valid groups are found.
      Raises ValueError if no data are selected.
  
      Parameters
      ----------
      groups: str or list of str, optional
          Groups where the transformation is to be applied. Can either be group names
          or metagroup names.
      filter_groups: {None, "like", "regex"}, optional, default=None
          If `None` (default), interpret groups as the real group or metagroup names.
          If "like", interpret groups as substrings of the real group or metagroup names.
          If "regex", interpret groups as regular expressions on the real group or
          metagroup names. A la `pandas.filter`.
      var_names : str or list of str, optional
          Variables to be extracted. Prefix the variables by `~` when you want to exclude them.
      filter_vars: {None, "like", "regex"}, optional
          If `None` (default), interpret var_names as the real variables names. If "like",
          interpret var_names as substrings of the real variables names. If "regex",
          interpret var_names as regular expressions on the real variables names. A la
          `pandas.filter`.
          Like with plotting, sometimes it's easier to subset saying what to exclude
          instead of what to include
      include_coords: bool
          Add coordinate values to column name (tuple).
      include_index: bool
          Add index information for multidimensional arrays.
      index_origin: {0, 1}, optional
          Starting index  for multidimensional objects. 0- or 1-based.
          Defaults to rcParams["data.index_origin"].
  
      Returns
      -------
      pandas.DataFrame
          A pandas DataFrame containing all selected groups of InferenceData object.
      """
      # pylint: disable=too-many-nested-blocks
      if not include_coords and not include_index:
          raise TypeError(
              "Both include_coords and include_index can not be False."
          )
      if index_origin is None:
          index_origin = rcParams["data.index_origin"]
      if index_origin not in [0, 1]:
          raise TypeError(
              f"index_origin must be 0 or 1, saw {index_origin}"
          )
  
      group_names = list(
          filter(
              lambda x: "data" not in x,
              self._group_names(groups, filter_groups),
          )
      )
  
      if not group_names:
          raise TypeError(f"No valid groups found: {groups}")
  
      dfs = {}
      for group in group_names:
          dataset = self[group]
          group_var_names = _var_names(
              var_names, dataset, filter_vars, "ignore"
          )
          if (group_var_names is not None) and not group_var_names:
              continue
          if group_var_names is not None:
              dataset = dataset[
                  [
                      var_name
                      for var_name in group_var_names
                      if var_name in dataset
                  ]
              ]
          df = None
          coords_to_idx = {
              name: dict(
                  map(
                      reversed,
                      enumerate(
                          dataset.coords[name].values, index_origin
                      ),
                  )
              )
              for name in list(
                  filter(
                      lambda x: x not in ("chain", "draw"),
                      dataset.coords,
                  )
              )
          }
          for data_array in dataset.values():
              dataframe = data_array.to_dataframe()
              if list(
                  filter(
                      lambda x: x not in ("chain", "draw"),
                      data_array.dims,
                  )
              ):
                  levels = [
                      idx
                      for idx, dim in enumerate(data_array.dims)
                      if dim not in ("chain", "draw")
                  ]
                  dataframe = dataframe.unstack(level=levels)
                  tuple_columns = []
                  for name, *coords in dataframe.columns:
                      if include_index:
                          idxs = []
                          for coordname, coorditem in zip(
                              dataframe.columns.names[1:], coords
                          ):
                              idxs.append(
                                  coords_to_idx[coordname][coorditem]
                              )
                          if include_coords:
                              tuple_columns.append(
                                  (
                                      f"{name}[{','.join(map(str, idxs))}]",
                                      *coords,
                                  )
                              )
                          else:
                              tuple_columns.append(
                                  f"{name}[{','.join(map(str, idxs))}]"
                              )
                      else:
                          tuple_columns.append((name, *coords))
  
                  dataframe.columns = tuple_columns
                  dataframe.sort_index(axis=1, inplace=True)
              if df is None:
                  df = dataframe
                  continue
              df = df.join(dataframe, how="outer")
          if df is not None:
              df = df.reset_index()
              dfs[group] = df
      if not dfs:
          raise ValueError("No data selected for the dataframe.")
      if len(dfs) > 1:
          for group, df in dfs.items():
              df.columns = [
                  col
                  if col in ("draw", "chain")
                  else (group, *col)
                  if isinstance(col, tuple)
                  else (group, col)
                  for col in df.columns
              ]
          dfs, *dfs_tail = list(dfs.values())
          for df in dfs_tail:
              dfs = dfs.merge(df, how="outer", copy=False)
      else:
          (
              dfs,
          ) = dfs.values()  # pylint: disable=unbalanced-dict-unpacking
      return dfs
  
imports: import os
  import re
  import sys
  import uuid
  import warnings
  from collections import OrderedDict, defaultdict
  from collections.abc import MutableMapping, Sequence
  from copy import copy
  from copy import deepcopy
  from datetime import datetime
  from html import escape
  from typing import TYPE_CHECKING, Any, Iterable, Iterator, List, Mapping, Optional, Tuple, TypeVar, Union, overload
  import numpy
  import xarray
  from packaging import version
  from ..rcparams import rcParams
  from ..utils import HtmlTemplate, _subset_list, _var_names, either_dict_or_kwargs
  from .base import _extend_xr_method, _make_json_serializable, dict_to_dataset
label_desc: Use image node_id 22 for calling the InferenceData obj's underlying member method code with example usage: obj.to_dataframe(groups, filter_groups, var_names, filter_vars, include_coords, include_index, index_origin) and returns: dfs