# from dataframe matrix_weak = matrix.copy() # to numpy arrays matrix_weak_to_numpy = matrix_weak.to_numpy() G = nx.from_numpy_matrix(matrix_weak_to_numpy) G = G.to_directed() # weakly connected component needs a directed
图表
max_wcc = max(nx.weakly_connected_components(G), key=len) max_wcc = nx.subgraph(G, max_wcc)
网络中的节点总数为 G.number_of_nodes()
G.number_of_nodes()
fraction = max_wcc.number_of_nodes() / G.number_of_nodes()