pyblp.data_to_dict

pyblp.data_to_dict(data, ignore_empty=True)

Convert a NumPy record array into a dictionary.

Most data in PyBLP are structured as NumPy record arrays (e.g., Problem.products and SimulationResults.product_data) which can be cumbersome to work with when working with data types that can’t represent matrices, such as the pandas.DataFrame.

This function converts record arrays created by PyBLP into dictionaries that map field names to one-dimensional arrays. Matrices in the original record array (e.g., demand_instruments) are split into as many fields as there are columns (e.g., demand_instruments0, demand_instruments1, and so on).

Parameters
  • data (recarray) – Record array created by PyBLP.

  • ignore_empty (bool, optional) – Whether to ignore matrices with zero size. By default, these are ignored.

Returns

The data re-structured as a dictionary.

Return type

dict

Examples