I have networkx v. 2.1
. to make it work w/ pandas dataframe, i tried following:
pip3
, this did not work generated
This solution helps as well:
G = nx.DiGraph()
G.add_weighted_edges_from([tuple(x) for x in x.values])
nx.info(G)
'Name: \nType: DiGraph\nNumber of nodes: 5713\nNumber of edges: 5000\nAverage in degree: 0.8752\nAverage out degree: 0.8752'
A simple graph:
import pandas as pd
import numpy as np
import networkx as nx
import matplotlib.pyplot as plt
# Build a dataframe with 4 connections
df = pd.DataFrame({'from': \['A', 'B', 'C', 'A'\], 'to': \['D', 'A', 'E', 'C'\]})
# Build your graph
G = nx.from_pandas_edgelist(df, 'from', 'to')
# Plot it
nx.draw(G, with_labels=True)
plt.show()
In networkx 2.0 from_pandas_dataframe
has been removed.
Instead you can use from_pandas_edgelist.
Then you'll have:
g_data=G=nx.from_pandas_edgelist(x, 1, 2, edge_attr=True)