You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何将成对共发表相关性CSV表转换为Neo4j/Cytoscape可导入的节点边表

Got it, let's break this down step by step—turning your 165x165 co-publication correlation CSV into node and edge tables for Neo4j or Cytoscape is totally doable, whether you prefer coding or no-code tools. First, let's confirm we're on the same page about your CSV structure: I'm assuming it's a square matrix where the first row and first column are author names, and each cross-cell is the correlation coefficient between two authors.

Step 1: Generate Standard Node & Edge Tables

Both Neo4j and Cytoscape rely on two core files:

  • Node Table: A list of unique authors (each author is a node)
  • Edge Table: A list of pairwise relationships, with the correlation as an attribute

Method 1: Python (Pandas) – Fast & Flexible

This is the best approach for large tables like your 165x165 one, since it automates cleanup.

Generate Node Table

import pandas as pd

# Load your correlation matrix CSV
df = pd.read_csv("your_correlation_matrix.csv", index_col=0)

# Extract unique author names for nodes
nodes = pd.DataFrame({
    "id": df.index.unique(),  # Unique ID for each node
    "label": df.index.unique()  # Display name (can match ID)
})

# Save node table
nodes.to_csv("authors_nodes.csv", index=False)

Pro tip: If you have extra author metadata (like affiliation), you can add those as additional columns here.

Generate Edge Table

We need to flatten the matrix into a list of source → target pairs, and clean up duplicates/self-correlations:

# Convert wide matrix to long format
edges = df.stack().reset_index()
edges.columns = ["source", "target", "correlation"]

# Remove self-correlations (author paired with themselves)
edges = edges[edges["source"] != edges["target"]]

# Remove duplicate pairs (e.g., Alice→Bob and Bob→Alice) – keep only one direction
edges = edges[edges["source"] < edges["target"]]

# Save edge table
edges.to_csv("co_author_edges.csv", index=False)

This gives you a clean list of unique co-publication relationships with their correlation values.


Method 2: Excel (No-Code)

If coding isn't your thing, Excel's Power Query can handle this:

Node Table

  1. Copy the first column of author names to a new worksheet
  2. Go to Data → Remove Duplicates to get a unique list of authors
  3. Add headers id and label (both can use the author name)
  4. Save as authors_nodes.csv

Edge Table

  1. Select your entire correlation matrix (including headers and first column)
  2. Go to Data → From Table/Range to open Power Query
  3. Select the author name column, then go to Transform → Unpivot Columns → Unpivot Other Columns
  4. Rename the columns: Attribute → target, Value → correlation, and the first column → source
  5. Filter out rows where source = target (self-correlations)
  6. To remove duplicate pairs, add a helper column with =IF([@source]<[@target],1,0), then filter for rows with 1
  7. Export the cleaned table as co_author_edges.csv

Import to Neo4j

Once you have your node and edge CSVs:

  1. Move both files to Neo4j's import folder (found in your database directory)
  2. Run these Cypher queries in the Neo4j Browser:
// Import author nodes
LOAD CSV WITH HEADERS FROM "file:///authors_nodes.csv" AS row
CREATE (a:Author {id: row.id, name: row.label});

// Import co-publication edges with correlation attribute
LOAD CSV WITH HEADERS FROM "file:///co_author_edges.csv" AS row
MATCH (a:Author {id: row.source}), (b:Author {id: row.target})
CREATE (a)-[:CO_PUBLISHED_WITH {correlation: toFloat(row.correlation)}]->(b);

Note: toFloat() converts the correlation value from a string to a numeric type for calculations later.


Import to Cytoscape

Cytoscape makes this super straightforward:

  1. Open Cytoscape, then drag-and-drop both authors_nodes.csv and co_author_edges.csv into the window
  2. Cytoscape will automatically detect:
    • id as the unique node identifier
    • source and target as the endpoints of each edge
    • correlation as an edge attribute
  3. You can then adjust styles (e.g., make edges thicker for higher correlation values) via the Style panel on the right.

内容的提问来源于stack exchange,提问作者user3050520

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.21 08:43:15