Sunday, 30 June 2019

Gephi: Importing csv file data


This is continuation to my previous post. In my previous post, I explained how to create data set using 'Data Laboratory' widget. But this widget is not much helpful for large data sets. As an alternative to that, you can define the data in .xls, Google spread sheets etc., conver the data into csv file and export the csv file into Gephi.

We need two csv files to define a graph in Gephi.
a.   Nodes csv file: Used to represent the node ids, labels etc.,
b.   Edges csv file : Define the edges information

Below step-by-step procedure explains how to create and import the csv files data into Gephi.

Step 1: Create and import nodes csv file
Create a node file using any of your favorite software (like Windows Excel, Google spread sheets etc.,)

Make sure that the node file has below fields.
         a. Id,
         b. Label and
         c. timeset

I created new xls file with above fields and populate some dummy data.



Save the file in .csv format. In Windows Excel use ‘File -> Save As’ and select the file type as csv.

nodesFile.csv
Id,Label,timeset
0,Chicago,
1,Detroit,
2,Boston,
3,New York,
4,Philadelphia,

Import the csv file
Open Gephi user interface.


File -> New Project. Go to Data Laboratory view. If Data Table is not visible to you, you can open it by following Window -> Data Table.



Select ‘Nodes’ widget and click on ‘Import Spreadsheet’ button.



Select the csv file and Click on Open button.

You should see something like below screen.


Press Next.




Press Finish button.

It shows the detailed report of imported file.


Select ‘Append to existing workspace’ radio button.

Press OK button.

Now you can able to see all the nodes information under nodes widget.


Step 2:  Create and import edges csv file
Create an edges csv file using any of your favorite software (like Windows Excel, Google spread sheets etc.,)

Make sure that the edges file has below fields.
         a. Source,
         b. Target,
         c. Type,
         d. Id,
         e. Label,
         f. timeset,
         g. Weight
        
Some fields like timeset, Weight are optional, you can ignore them if you want.

edgesFile.csv
Source,Target,Type,Id,Label,timeset,Weight
0,1,Undirected,0,,,1
0,3,Undirected,1,,,1
0,4,Undirected,2,,,1
1,2,Undirected,3,,,1
1,3,Undirected,4,,,1
2,3,Undirected,5,,,1
2,4,Undirected,6,,,1
3,4,Undirected,7,,,1

Import edgesFile.csv to Gephi interface.

Go to Data Laboratory view. Select ‘Edges’ tab and click on ‘Import Spreadsheet’ button.


Select the csv file that you want to open.


Press ‘Open’ button.


It opens below kind of window.



Press Next button.



Press Finish button.


It opens Report window.


Select ‘Append to existing workspace’ radio button.

Press OK button.

You can able to see all the edges information.


Step 3: View the graph.

Go to Overview section and enable node labels, you can able to see below kind of graph.


That’s it you are done. In my next post, I am going to explain how can you import data from sql databases.
Previous                                                 Next                                                 Home

No comments:

Post a Comment