1.2.10. patsy.LookupFactor

class patsy.LookupFactor(varname, force_categorical=False, contrast=None, levels=None, origin=None)[source]

A simple factor class that simply looks up a named entry in the given data.

Useful for programatically constructing formulas, and as a simple example of the factor protocol. For details see expert-model-specification.

Example:

dmatrix(ModelDesc([], [Term([LookupFactor("x")])]), {"x": [1, 2, 3]})
Parameters:
  • varname – The name of this variable; used as a lookup key in the passed in data dictionary/DataFrame/whatever.
  • force_categorical – If True, then treat this factor as categorical. (Equivalent to using C() in a regular formula, but of course you can’t do that with a LookupFactor.
  • contrast – If given, the contrast to use; see C(). (Requires force_categorical=True.)
  • levels – If given, the categorical levels; see C(). (Requires force_categorical=True.)
  • origin – Either None, or the Origin of this factor for use in error reporting.

New in version 0.2.0: The force_categorical and related arguments.

__init__(varname, force_categorical=False, contrast=None, levels=None, origin=None)[source]

1.2.10.1. Methods

__init__(varname[, force_categorical, ...])
eval(memorize_state, data)
memorize_chunk(state, which_pass, data)
memorize_finish(state, which_pass)
memorize_passes_needed(state, eval_env)
name()