0

I stumbled upon this image representing deputies' voting patterns: enter image description here

From what I understand, deputies with similar voting patterns would be placed closer on the graph.

Given I have tabular data with name, vote, and vote_id columns, i) how do I create edges and nodes from it, ii) how do I create graph drawing from those edges and nodes?

I think I'll need to use networkx module once I transform the data, but I'm not sure how to create connections first.

I'm sorry in advance if it's obvious, I only recently discovered network analysis.


Some sample data if that helps:

  name        vote  vote_id
0    A         yes        1
1    A         yes        2
2    B          no        1
3    B  not voting        2
4    C  not voting        1
5    C          no        2
6    D         yes        1
7    D          no        2
help-ukraine-now
  • 3,850
  • 4
  • 19
  • 36
  • 1
    Your nodes will correspond to the the `name` attributes. However, w.r.t to the edges you will have to make a choice. Presumably, the edge weight is some measure of the similarity in the voting pattern but there are many similarity measures to choose from. In your case, the cosine similarity would probably the most natural choice. There are implementations in `scipy.spatial.pdist` and `scikit-learn` that you could use. – Paul Brodersen Nov 01 '19 at 15:42
  • 1
    To compute a voting pattern for a given `name`, you would create a vector of length unique `vote_id`, and populate it with the person's votes (e.g. yes : 1, not voting : 0, no : -1, none : NaN). You would then compute the cosine similarity between two such voting patterns, which you would then use as the edge weight for the edge between the two corresponding names. Note that you will need to properly deal with the NaNs; a discussion can be found [here](https://stackoverflow.com/questions/24781461/compute-the-pairwise-distance-in-scipy-with-missing-values?noredirect=1&lq=1). – Paul Brodersen Nov 01 '19 at 15:47
  • @PaulBrodersen, thanks so much. I'll look into that! – help-ukraine-now Nov 01 '19 at 15:50

0 Answers0