Pandas

class hamilton.base.PandasDataFrameResult

Mixin for building a pandas dataframe from the result.

It returns the results as a Pandas Dataframe, where the columns map to outputs requested, and values map to what was computed for those values. Note: this only works if the computed values are pandas series, or scalar values.

Use this when you want to create a pandas dataframe.

Example:

from hamilton import base, driver
df_builder = base.PandasDataFrameResult()
adapter = base.SimplePythonGraphAdapter(df_builder)
dr =  driver.Driver(config, *modules, adapter=adapter)
df = dr.execute([...], inputs=...)
static build_result(**outputs: Dict[str, Any]) DataFrame

Builds a Pandas DataFrame from the outputs.

This function will check the index types of the outputs, and log warnings if they don’t match. The behavior of pd.Dataframe(outputs) is that it will do an outer join based on indexes of the Series passed in.

Parameters:

outputs – the outputs to build a dataframe from.

class hamilton.base.StrictIndexTypePandasDataFrameResult

A ResultBuilder that produces a dataframe only if the index types match exactly.

Note: If there is no index type on some outputs, e.g. the value is a scalar, as long as there exists a single pandas index type, no error will be thrown, because a dataframe can be easily created.

Use this when you want to create a pandas dataframe from the outputs, but you want to ensure that the index types match exactly.

To use:

from hamilton import base, driver
strict_builder = base.StrictIndexTypePandasDataFrameResult()
adapter = base.SimplePythonGraphAdapter(strict_builder)
dr =  driver.Driver(config, *modules, adapter=adapter)
df = dr.execute([...], inputs=...)  # this will now error if index types mismatch.
static build_result(**outputs: Dict[str, Any]) DataFrame

Builds a Pandas DataFrame from the outputs.

This function will check the index types of the outputs, and log warnings if they don’t match. The behavior of pd.Dataframe(outputs) is that it will do an outer join based on indexes of the Series passed in.

Parameters:

outputs – the outputs to build a dataframe from.