![]() G.add_nodes_from(node_names) adds node names from our node_names list.NetworkX will allow us to combine those lists in a network analysis, a Graph data object in NetworkX.ġ1-Use G=nx.Graph() to initialize a Graph object. Print(len(edges)) # prints the total count of edgesĩ-If you reopened the CSV files, you could confirm that Python had correctly loaded 119 node names (number of rows in the nodelist file) and 174 edges (number of rows in the edgelist file).ġ0-Right now, we have a list of nodes (node_names) and a list of edges (edges) in Python. print(len(node_names)) # prints the count of node names The additional indented lines read the CSV data, analyze the node names, retrieve the edge data, and remove the descriptive header information.ħ-From these commands, we have a list of node names and edge pairs which will be the foundation of our network analysis.Ĩ-Before moving forward, let’s check to make sure our data has loaded correctly into Python. With open('quakers_edgelist.csv', 'r') as edgecsv: # Open the fileĮdgereader = csv.reader(edgecsv) # Read the csvĮdges = # Retrieve the dataĦ-With open opens our CSV files in the read (‘r’) mode and creates lists named nodecsv and edgecsv with that data. Node_names = for n in nodes] # Get a list of only the node names Nodereader = csv.reader(nodecsv) # Read the csv # Retrieve the data (using Python list comprehension and list slicing to remove the header row) with open('quakers_nodelist.csv', 'r') as nodecsv: # Open the file Feel free to re-type this code, but you can also copy and paste from the online WordPress tutorial. import csvĤ-CSV and itemgetter are built-in Python libraries, and we installed the NetworkX and Community libraries in the first part of this tutorial.ĥ-Now we’ll add code that tells Python to open the nodelist and edgelist CSV files and read the data contained in those files. Copy or move those files into your Python directory (C:Python…) using File Explorer.Ģ-Click Start->All Programs->Python->IDLE (Python) to open Python’s GUI coding interface.ģ-Start your Python file by importing the libraries and packages we’ll need to use NetworkX. If you want to install Python or NetworkX on your own computer, consult The Programming Historian’s tutorial for additional instructions.ġ-We will be working with the same nodelist and edgelist CSV files we downloaded at the start of this tutorial. Type pip install community in the command prompt window and hit the Enter key to install the Community Python library.Ĭlose the command prompt window after the install has completed. Type pip install networkx in the command prompt window and hit the Enter key to install the NetworkX Python library. Type cmd in the File Explorer navigation bar, and hit the Enter key. To install NetworkX, navigate to C:\Python27\Scripts in File Explorer. Python is already installed on the Library lab computers. Navigate to \storageprojectsHISHIS-295-02Quaker_Network_Data and copy the quakers_nodelist and quakers_edgelist CSV files to your Desktop. ![]() These data sets include a list of names and relationships for early seventeenth-century Quakers. We will be working with sample networked data sets based on the Oxford Dictionary of National Biography and the Six Degrees of Francis Bacon project. NetworkX is a free Python library developed and released in 2005. In the next section of the tutorial, we will be using NetworkX, a Python package, to analyze and study more complex aspects of the Quaker data. But, larger data sets or more complex analysis often goes beyond the capacity of a GUI tool. GUI interfaces like Palladio and Gephi help researchers use digital tools quickly without requiring extensive technical documentation. Network Analysis-Part II (NetworkX) is licensed under a Creative Commons Attribution-NonCommercial 4.0 International License. This tutorial is adapted from the Programming Historian’s Exploring and Analyzing Network Data with Python tutorial. Parker Professor of History) and Gina Donovan (Instructional Technologist) at Grinnell College, and edited by Papa Ampim-Darko, a student research assistant at Grinnell College. This tutorial was reviewed by Sarah Purcell (L.F. This tutorial was written by Katherine Walden, Digital Liberal Arts Specialist at Grinnell College.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |