Categories
Uncategorized

Links Between Networks – Python

I have 43 networks where some of the actors overlap, and what I would like to do is to visualise this overlap. The problem is that these networks combined will have more that 40,000 nodes, so it will be very messy to stick everything into one network graph. So the next best thing is to […]

Categories
Uncategorized

Mathematical Combination – Python

The idea is to print all the different combinations from a series of numbers in a list (order not important). This script will be used to automate the comparison of 40+ networks on a list :D So, if we start with a series of 1 to 5, what we want to get is So here […]

Categories
Uncategorized

Draw Quick Graph with igraph – Python

You start with a pajek file, called something_pajek.net, then you run this code. You should end up with something like this.

Categories
Uncategorized

Input from file, then move files – Python

This bit of code will take the input from a file, create a series of files with matching directories (folders), then move the file into the directory (easier than changing the directory) The input file reads… This is the Python code… So you should end up with something like this

Categories
Uncategorized

Getting MySQL and Python to work on Mac OS X Mountain Lion

Python comes pre-installed. So half the job is done there. Installing MySQL is pretty easy if you’re using Homebrew (which I am). You may have to do that as a super user….which means you have to add sudo to the start of the line. Next step is to get MySQL to talk to Python. For […]

Categories
Uncategorized

Reformatting dates – Python

This little script will reformat a series of dates in a file, from 22 April 1980 to a more compact 19800422 ([yyyymmdd]) ISO standard, using the re and time libraries. Start with a file containing a series of dates Then this is the python code Now the output file will read

Categories
Uncategorized

Graph Degree Centrality iGraph – Pythom

This Python code will read a Pajek graph and calculate its degree centrality using this formula … To test the result I will be using example 17 from Freeman’s (1978) Centrality in Social Networks: Conceptual Clarification. Freeman’s calculation for this example is 0.42. The graph is written in a file named graph17.net, which reads: This […]

Categories
Uncategorized

Calculating Degree Centrality Using Data Frames – Python

Calculating Freeman’s degree centrality for each node… …and for the graph. All the information is contained in an external file graph.csv, which contains this Where the “freq” column is the number of edges adjacent to the node. To find node centrality This script outputs the file data_graph.csv with the following information: Where CD is the […]

Categories
Uncategorized

Edit a Bunch of Files – Python

I have four files in the folder and I want to write Number into each one of them. So this bit of code will open each one of them and write Number and the value of counter (so we know it’s doing it’s thing). We cd to the folder and run the script. The result […]

Categories
Uncategorized

Installing python-iGraph module – Python

For OS X – Mountain Lion Save yourself a freaking headache Install Brew. Install the iGraph C library Install pip Python package manager Now for the iGraph Python library