Skip to content
This repository has been archived by the owner on Mar 5, 2024. It is now read-only.

create graph from file (other than CSV) #4

Open
yaslena opened this issue Sep 13, 2021 · 0 comments
Open

create graph from file (other than CSV) #4

yaslena opened this issue Sep 13, 2021 · 0 comments
Labels

Comments

@yaslena
Copy link
Collaborator

yaslena commented Sep 13, 2021

Module description
Creates a graph from a file that contains all information on the graph structure.

This can be a graphml file, a gefx file (Gephi file), or a json file (could also add csv here).

Inputs

  • the type of the file from which the graph is created (graphml, gefx..)
  • path to file
  • column names for source and target
  • optional: any other columns to be considered
  • graph type (often: multigraph or not multigraph)
  • for some file formats: data type of columns (str, int ..)
  • for gefx: version of Gephi
  • for gefx: use Gephi "id" or "label" columns as labels in networkX

Graph types
Affects all graph types.

Outupts
The output is a graph.

Example code

  1. graphml

1.1. igraph:
Gix = ig.read('graph.graphml', format='graphml') #this creates an igraph graph (not a networkX graph) from a graphml file, indicate file name and type.

1.2. networkX:
G = nx.read_graphml(path, node_type=<class 'str'>, edge_key_type=<class 'int'>, force_multigraph=False)

  1. csv with pandas

edges = pd.read_csv('JournalEdges1902.csv') #read csv with pandas and create df (should be an edge list representation of a graph)
G = nx.from_pandas_edgelist(edges, "Source", "Target", edge_attr=True, create_using=nx.DiGraph()) #then create graph indicating the pandas df, mapping the columns, and indicating graph type

  1. gefx

G = nx.read_gexf(path, node_type=None, relabel=False, version='1.2draft')

@yaslena yaslena added the module label Sep 13, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

1 participant