face2face.imports.create_network.create_network_from_data

face2face.imports.create_network.create_network_from_data(Data, replace_attr=False, label=None)

Allow to create a networkx Graph

Creating a networkx graph based on the interaction data. Metadata can also be provided to add node attributes.

Parameters
  • Data (Data) – Data Object that contains Tij- and Metadata for a dataset.

  • replace_attr (bool) – If True, attributes of type string will be replaced by float numbers.

  • label (optional, string) – If string label is given, the rows where label column value is NaN will be removed before creating the network.

Returns

G – A graph with a specified degree sequence. Nodes are labeled based on the imported dataset.

Return type

NetworkX Graph

Examples

>>> attr_list = ["ID", "Age", "Sex"]
>>> test_df = Data(path_tij="face2face/data/Test/tij_test.dat", separator_tij="\t",
>>>                path_meta="face2face/data/Test/meta_test.dat", separator_meta="\t",
>>>                meta_attr_list=attr_list)
>>> test_network = create_network_from_data(test_df)
>>> print(test_network.edges)
[(0, 1), (1, 2), (1, 3), (2, 3), (4, 6), (4, 7), (6, 7), (10, 11), (10, 12), (11, 12)]
>>> print(test_network.nodes)
[0, 1, 2, 3, 4, 6, 7, 10, 11, 12]
>>> for i in test_network.nodes:
    >>> print(test_network.nodes[i])
{'Age': 1.0, 'Sex': 1.0}
{'Age': 0.0, 'Sex': 'NaN'}
{'Age': 'NaN', 'Sex': 0.0}
{'Age': 0.0, 'Sex': 1.0}
{'Age': 'NaN', 'Sex': 0.0}
{'Age': 1.0, 'Sex': 1.0}
{'Age': 1.0, 'Sex': 'NaN'}
{'Age': 2.0, 'Sex': 1.0}
{'Age': 2.0, 'Sex': 0.0}
{'Age': 2.0, 'Sex': 1.0}