graphical_models.classes.dags.dag.DAG.from_dataframe
- classmethod DAG.from_dataframe(df)[source]
Create a DAG from a dataframe, where the indices and columns are node names and a nonzero entry indicates the presence of an edge.
- Parameters
df – The pandas dataframe.
- Returns
The graph as a DAG object.
- Return type
DAG
Examples
>>> from graphical_models import DAG >>> import numpy as np >>> import pandas as pd >>> amat = np.array([[0, 1], [0, 0]]) >>> df = pd.DataFrame(amat, index=["a", "b"], columns=["a", "b"]) >>> d = DAG.from_dataframe(df) >>> d.arcs {('a', 'b')}