liveBook · Manning

Load csv clause

As explained in Graph Algorithms for Data Science

The LOAD CSV clause is a Cypher language construct that reads rows from local or internet-accessible CSV files.

LOAD CSV reads rows from local or internet-accessible CSV files and exposes each row for later Cypher operations. Files may include headers or omit them: header rows produce map-like values, while headerless rows produce lists. Use FIELDTERMINATOR for custom delimiters. section 3.2.4

Use the clause with these practical considerations:

  • Publicly accessible files can be fetched directly; LOAD CSV provides no authorization support. section 3.2.4
  • All imported values arrive as strings, so convert identifiers, dates, and other values to suitable types in the import query. section 3.2.4
  • Combine LOAD CSV with MERGE and ON CREATE SET to make imports handle duplicates more safely. section 3.2.5
  • For larger files, use a Cypher subquery with IN TRANSACTIONS to divide work into batches and reduce memory pressure. section 3.2.5

Inspect the first rows

LOAD CSV WITH HEADERS FROM "https://example.org/users.csv" AS row WITH row LIMIT 5 RETURN row The same pattern supports graph imports: match existing nodes, merge new nodes or relationships, and convert values such as timestamps with datetime().

Listing 3.36 Cypher query that fetches and displays information from a CSV file
LOAD CSV WITH HEADERS FROM "https:/ /bit.ly/39JYakC" AS row
WITH row
LIMIT 5
RETURN row

Inspect a complete query that fetches a header-based CSV file, limits the preview to five rows, and returns each row. section 3.2.4

How Graph Algorithms for Data Science covers it

How deep it goes
Explains headers, delimiters, strings, type conversion, duplicate handling, and transaction batching with executable imports.
Examples
Demonstrates previewing CSV rows and importing users, tweets, follows, mentions, retweets, and replies.
What you can do after
Build it from scratch by previewing CSV data and loading typed nodes and relationships into a graph.
How it connects
Connects CSV loading with Cypher maps, lists, FIELDTERMINATOR, LIMIT, MERGE, datetime, Cypher subqueries, and IN TRANSACTIONS.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Graph Algorithms for Data Science. The section links point to the parts of the book it draws on.