I am trying to pass a list of values into a Py2neo Cypher query, and use that list as a parameter of the query. I'm having some difficulty at the moment. I'm attempting to pass in a list of company to the query, and return the query results to a Pandas DataFrame.
The code I am using currently is seen below. The list of companies here is shortened for demonstration purposes and is in fact hundreds of companies long.
my_list = ['Company_1','Company_2','Company_3','Company_4']
my_query = '''(c1:Company)-[r:HAS_SUPPLIER]-(c2:Company) where
c1.name in ['{mylist}'] Return c1.name, r.rank, c2.name'''
company_df = graph.cypher.execute(my_query)
company_df = pd.DataFrame(company_df .records, columns=company_df.columns)
The error message I am receive is as follows:
AttributeError: module 'py2neo.cypher.error.statement' has no attribute 'SyntaxError'
Any assistance that someone could provide would be greatly appreciated.
Can you try this :
params = {}
params['mylist'] = ['Company_1','Company_2','Company_3','Company_4']
my_query = '(c1:Company)-[r:HAS_SUPPLIER]-(c2:Company) where
c1.name in $mylist Return c1.name, r.rank, c2.name'
company_df = graph.cypher.execute(my_query, params)