Don't know how to correct my code


This worked:
// Creating recipient nodes for all recipients with old and new balances
LOAD CSV WITH HEADERS FROM 'file:///fraud_detection.csv' AS row
MERGE (r:Recipient {
R_ID: row.nameDest,
oldBalance: toFloat(row.oldbalanceDest),
newBalance: toFloat(row.newbalanceDest)
})

// Creating customer nodes with new and old balances
LOAD CSV WITH HEADERS FROM 'file:///fraud_detection.csv' AS row
MERGE (c:Customer {
C_ID: row.nameOrig,
oldBalance: toFloat(row.oldbalanceOrg),
newBalance: CASE WHEN trim(row.newbalanceOrg) <> '' THEN toFloat(row.newbalanceOrg) ELSE 0.0 END
})

I;m having an error in this:
// Creating transaction nodes with type and relationships
LOAD CSV WITH HEADERS FROM 'file:///fraud_detection.csv' AS row

// Iterate over rows and conditionally create nodes and relationships
FOREACH(ignoreMe IN CASE WHEN row.steps IS NOT NULL AND trim(row.steps) <> '' THEN [1] ELSE END |
MERGE (t:Transaction {
steps: toInteger(row.steps),
T_type: row.T_type, // Keep 'type' as it is
amount: toFloat(row.amount),
isFraud: toInteger(row.isFraud)
})

// Conditional CREATE for customer node
MERGE (customer:Customer { C_ID: row.nameOrig })

// Conditional CREATE for recipient node
MERGE (recipient:Recipient { R_ID: row.nameDest })

// Create relationships
WITH t, customer, recipient
MERGE (customer)-[:MADE]->(t)
WITH t, recipient
MERGE (t)-[:RECEIVED]->(recipient);
);
"WITH" (line 14, column 37 (offset: 568))
" MERGE (t)-[:RECEIVED]->(recipient)"

if anyone can provide a solution or better query much appreciated

I doubt you can have a “with” clause in a “forEach” code block. I know you can’t “match”. Its purpose is to loop through a list and perform some actions like “merge”, “create”, or “set”.

You can use a call subquery instead to skip this block of code when your condition is true.

You also don’t need the “with” clause where you have them, so just remove them from the “forEach” block.

Or, try this:

LOAD CSV WITH HEADERS FROM 'file:///fraud_detection.csv' AS row
CALL {
    with row
    with row
    where row.steps IS NOT NULL AND trim(row.steps) <> ''
    
    MERGE (t:Transaction {
        steps: toInteger(row.steps),
        T_type: row.T_type,
        amount: toFloat(row.amount),
        isFraud: toInteger(row.isFraud)
    })

    MERGE (customer:Customer { C_ID: row.nameOrig })
    MERGE (recipient:Recipient { R_ID: row.nameDest })

    MERGE (customer)-[:MADE]->(t)
    MERGE (t)-[:RECEIVED]->(recipient)
}

Actually, you don’t need the subquery since your code isn’t doing anything after the subquery. This should work as well.

LOAD CSV WITH HEADERS FROM 'file:///fraud_detection.csv' AS row
 with row
 where row.steps IS NOT NULL AND trim(row.steps) <> ''
    
    MERGE (t:Transaction {
        steps: toInteger(row.steps),
        T_type: row.T_type,
        amount: toFloat(row.amount),
        isFraud: toInteger(row.isFraud)
    })

    MERGE (customer:Customer { C_ID: row.nameOrig })
    MERGE (recipient:Recipient { R_ID: row.nameDest })

    MERGE (customer)-[:MADE]->(t)
    MERGE (t)-[:RECEIVED]->(recipient)