Here is my toy nodes dataframe:
import pandas as pd
df = pd.DataFrame({
'id': [1, 2, 3, 4, 5],
'a': [55, 2123, -19.3, 9, -8],
'b': ['aa', 'bb', 'ad', 'kuku', 'lulu']
})
I am building a Graph with the nodes (each row of the df is a node with id and attributes):
import networkx as nx
G = nx.Graph()
for i, attr in df.set_index('id').iterrows():
G.add_node(i, **attr.to_dict())
Now I want to connect these nodes using nodes similarity (cosine or any other distance function). Questions:
- Can I do nodes similarity with mixed types and apply different distance metrics for each type?
- If my node's attributes are all numbers, how can I calculate the similarity between any 2 nodes in my graph and draw an edge if similarity between node 1 and 2 is above some threshold alpha?
For question 2 consider my above df is:
df = pd.DataFrame({
'id': [1, 2, 3, 4, 5],
'a': [55, 2123, -19.3, 9, -8],
'b': [21, -0.1, 0.003, 4, 2.1]
})