msticpy.transform.network module

Module for converting DataFrame to Networkx graph.

msticpy.transform.network.df_to_networkx(data: DataFrame, source_col: str, target_col: str, source_attrs: Iterable[str] | None = None, target_attrs: Iterable[str] | None = None, edge_attrs: Iterable[str] | None = None, graph_type: typing_extensions.Literal[graph, digraph] = 'graph')

Create a networkx graph from a DataFrame.

Parameters:
  • data (pd.DataFrame) – Input data

  • source_col (str) – Column for source nodes.

  • target_col (str) – Column for target nodes.

  • source_attrs (Optional[List[str]], optional) – Optional list of columns to use as source node attributes, by default None

  • target_attrs (Optional[List[str]], optional) – Optional list of columns to use as target node attributes, by default None

  • edge_attrs (Optional[List[str]], optional) – Optional list of columns to use as edge node attributes, by default None

  • graph_type (str) – “graph” or “digraph” (for nx.DiGraph)

Returns:

The networkx graph object

Return type:

nx.Graph