In [65]:
import pandas as pd 
import networkx as nx 
import pickle

In [14]:
df_n = pd.read_csv('stars_main_nodes.csv')
df_e = pd.read_csv('stars_main_edges.csv')

In [30]:
# making a simple test graph from stars node/edge csv

In [67]:
G = nx.from_pandas_dataframe(df_e, 'source', 'target')

In [68]:
node_attr_list = df_n.to_dict('records')

In [69]:
n_id = 0
for i in G.nodes_iter(data=True):
    i[1]['label'] = node_attr_list[n_id]['label']
    i[1]['node_type'] = node_attr_list[n_id]['node_type']
    n_id += 1

In [70]:
pickle.dump(G,open('stars_test_graph.pkl','wb'))

In [74]:
df_n['node_type'].unique().tolist()


Out[74]:
['Author', 'Journal']

In [82]:
import random
r = lambda: random.randint(0,255)
print('#%02X%02X%02X' % (r(),r(),r()))


#2B1FE5

In [85]:
gg = nx.Graph()

gg.add_edge(0,1)
gg.add_edge(1,2)
gg.add_edge(1,3)
gg.add_node(0,{'node_type':'A', 'label':'node0'})
gg.add_node(1,{'node_type':'A', 'label':'node1'})
gg.add_node(2,{'node_type': 'B', 'label':'node2'})
gg.add_node(2,{'node_type': 'B', 'label':'node2'})

In [87]:
gg.nodes(data=True)


Out[87]:
[(0, {'node_type': 'A'}), (1, {'node_type': 'B'}), (2, {'node_type': 'C'})]

In [101]:
df_n.iloc[:1]['node_type'][0] == df_n.iloc[:1]['node_type'][0]


Out[101]:
True

In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]: