dimod.BinaryQuadraticModel.to_pandas_dataframe¶
-
BinaryQuadraticModel.to_pandas_dataframe()[source]¶ Convert a binary quadratic model to pandas DataFrame format.
Returns: The binary quadratic model as a DataFrame. The DataFrame has binary vartype. The rows and columns are labeled by the variables in the binary quadratic model. Return type: pandas.DataFrameNotes
The DataFrame representation of a binary quadratic model only makes sense for binary models. For a binary sample x, the energy of the model is given by:
\[E(x) = x^T Q x\]The offset is dropped when converting to a pandas DataFrame.
Examples
This example converts a binary quadratic model to pandas DataFrame format.
>>> import dimod >>> model = dimod.BinaryQuadraticModel({'a': 1.1, 'b': -1., 'c': .5}, ... {('a', 'b'): .5, ('b', 'c'): 1.5}, ... 1.4, ... dimod.BINARY) >>> model.to_pandas_dataframe() # doctest: +SKIP a b c a 1.1 0.5 0.0 b 0.0 -1.0 1.5 c 0.0 0.0 0.5