xarray.Dataset.to_dict

xarray.Dataset.to_dict#

Dataset.to_dict(data='list', encoding=False)[source]#

Convert this dataset to a dictionary following xarray naming conventions.

Converts all variables and attributes to native Python objects Useful for converting to json. To avoid datetime incompatibility use decode_times=False kwarg in xarrray.open_dataset.

Parameters:
  • data (bool or {"list", "array"}, default: "list") – Whether to include the actual data in the dictionary. When set to False, returns just the schema. If set to “array”, returns data as underlying array type. If set to “list” (or True for backwards compatibility), returns data in lists of Python data types. Note that for obtaining the “list” output efficiently, use ds.compute().to_dict(data=”list”).

  • encoding (bool, default: False) – Whether to include the Dataset’s encoding in the dictionary.

Returns:

d (dict) – Dict with keys: “coords”, “attrs”, “dims”, “data_vars” and optionally “encoding”.