Larch has two closely related interfaces to manage data: DataFrames and DataService. The former is a set of related data tables, while the latter is an interface that generates instances of the former. You can think of a DataService as a place to get data, and DataFrames as the data you get.

In fact, DataFrames is itself a subclass of DataService, allowing you to pull subsets of the data you have stored, so you can use DataFrames in both places.

A Larch Model object will generally have a DataService attached by the user, and then it will use that DataService to automatically generate, format, and pre-process the particular DataFrames it needs for analysis.

class larch.DataService

An object that implements the DataService interface must provide these methods.

make_dataframes(req_data, *, selector=None, float_dtype=numpy.float64)

Create a DataFrames object that will satisfy a data request.

  • req_data (Dict or str) – The requested data. The keys for this dictionary may include {‘ca’, ‘co’, ‘choice_ca’, ‘choice_co’, ‘weight_co’, ‘avail_ca’, ‘standardize’}. Currently, the keys {‘choice_co_code’, ‘avail_co’} are not implemented and will raise an error. Other keys are silently ignored.
  • selector (array-like[bool] or slice, optional) – If given, the selector filters the cases. This argument can only be given as a keyword argument.
  • float_dtype (dtype, default float64) – The dtype to use for all float-type arrays. Note that the availability arrays are always returned as int8 regardless of the float type. This argument can only be given as a keyword argument.
Return type:



This object should satisfy the request.