import networkx as nx G = nx.from_pandas_edgelist(df, 'node_1', 'node_2') print(G.number_of_nodes()) print(G.number_of_edges())