DataFrame

class amplpy.DataFrame(index, columns=(), **kwargs)

A DataFrame object, used to communicate data to and from the AMPL entities.

Warning

DataFrame objects should not be instantiated manually. For best performance using Python native types or Pandas DataFrames. The API takes care of the conversion for you in the most efficient way it finds.

An object of this class can be used to do the following tasks:

  • Assign values to AMPL entities (once the DataFrame is populated, use set_data() to assign its values to the modelling entities in its columns)

  • Get values from AMPL, decoupling the values from the AMPL entities they originate via get_values().

A DataFrame object can be created in various ways:

and can be converted to various object types:

to_dict()

Return a dictionary with the DataFrame data.

to_list(skip_index=False)

Return a list with the DataFrame data.

Args:

skip_index: set to True to retrieve only values.

to_pandas(multi_index=True)

Return a pandas.DataFrame with the DataFrame data.

classmethod from_dict(dic, index_names=None, column_names=None)

Create a DataFrame from a dictionary.

Args:

dic: dictionary to load. index_names: index names to use. column_names: column names to use.

classmethod from_pandas(df, index_names=None, indexarity=None)

Create a DataFrame from a pandas DataFrame.

Args:

df: Pandas DataFrame to load. index_names: index names to use.

classmethod from_numpy(data)

Create a DataFrame from a numpy array or matrix.

__annotations__ = {}