came.utils.preprocess.make_bipartite_adj

came.utils.preprocess.make_bipartite_adj(df_map: DataFrame, nodes1=None, nodes2=None, key_data: str | None = None, with_singleton: bool = True, symmetric: bool = True)

Make a bipartite adjacent (sparse) matrix from a pd.DataFrame with two mapping columns.

Parameters:
  • df_map (pd.DataFrame with 2 columns.) – each row represent an edge between 2 nodes from the left and right group of nodes of the bipartite-graph.

  • nodes1 (list-like) – node name-list representing left and right nodes, respectively.

  • nodes2 (list-like) – node name-list representing left and right nodes, respectively.

  • key_data (str or None) – if provided, should be a name in df.columns, where the values will be taken as the weights of the adjacent matrix.

  • with_singleton – whether allow nodes without any neighbors. (default: True) if nodes1 and nodes2 are not provided, this parameter makes no difference.

  • symmetric – whether make it symmetric, i.e. X += X.T

Examples

>>> bi_adj, nodes1, nodes2 = make_bipartite_adj(df_map)