1

Is there a way to put my cypher query into a python variable? I am able to put the non-parameter of the cypher into a variable but getting the error [![enter image description here][1]][1]

[1]: https://i.stack.imgur.com/mfRrp.png on trying to put the parameter part into a variable.

I am using pandas and py2neo to load a CSV into neo4j. df_data is my pandas dataframe with 2 columns and 3 rows.

for index,row in df_data.iterrows():
        tx.evaluate('''MERGE (x:PATIENT_ID {property:$PATIENT_ID})
            MERGE(y:GLB_ID {property:$GLB_ID})
            MERGE (x)-[r:R_TYPE]->(y) ''', parameters = {'PATIENT_ID': int(row['PATIENT_ID']), 'GLB_ID': int(row['GLB_ID'])})

My code runs without issues if I run the following code storing non-parameter part into cq:

for index,row in df_data.iterrows():
        tx.evaluate(cq, parameters = {'PATIENT_ID': int(row['PATIENT_ID']), 'GLB_ID': int(row['GLB_ID'])})

I am looking for a way to store the parameter part into a python variable

RB17
  • 356
  • 1
  • 8
  • 26
  • 1
    So you want to get the keynames: PATIENT_ID and GLB_ID from the dataframe and use it as keys to the dictionary of parameters being passed to neo4j? – jose_bacoy Mar 15 '21 at 18:01

1 Answers1

0

I used dictionary to get this resolved. I used dictionary over the cypher query to get it resolved:

for index,row in df_data.iterrows():
        t_dict = {}
        for k in p_dict.keys():
            try: 
                t_dict[k] = int(row[k])
            except TypeError:
                t_dict[k] = row[k]
        tx.evaluate(cq,t_dict)
RB17
  • 356
  • 1
  • 8
  • 26