Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
06-21-2021 01:34 PM
Hello,
I am have a Python program that reads data from an Oracle database into a Pandas DataFrame.
I then use Cypher to unwind the rows and create nodes with properties.
Sometimes the values returned from Oracle are null. In the case of numeric fields, the value of the property gets set to NaN.
Is there a way in Cypher to test a value in the unwound row and only create the property if the value meets a certain condition?
Thanks!
06-22-2021 02:10 AM
06-23-2021 05:22 AM
Thanks!
Example code would be really helpful.
06-23-2021 06:16 AM
Sure, but should give us your current Cypher query...
06-23-2021 07:57 AM
The query is below. I pass in a Pandas DataFrame that is populated from a query to Oracle. If a numeric field in Oracle is null, the DataFrame contains nan. These get created a properties with a value of NaN in Neo4j. I tried changing the nan to None in the DataFrame. WIth that, the properties get created with 0.0 as the value.
What I would really like to do is only create the property if there is a value.
Thanks!
def createEntries(rows, batch_size=10000):
query = '''UNWIND $rows AS row
CREATE (:Entry
{EntryNumber: row.ENTRY_NBR,
filer: row.FILER,
port_ent2: row.PORT_ENT,
entry_date: row.ENTRY_DATE,
entry_type: row.ENTRY_TYPE,
entry_val: row.ENTRY_VAL,
cr_entry_val: row.CR_ENTRY_VAL,
imp_nbr: row.IMP_NBR,
imp_id: row.IMP_ID,
imp_addr: row.IMP_ADDR,
cgn_nbr: row.CGN_NBR,
ult_cgn_id: row.ULT_CGN_ID,
ult_cgn_addr: row.ULT_CGN_ADDR,
entry_type: row.ENTRY_TYPE,
gross_wt: row.GROSS_WT,
est_duty: row.EST_DUTY,
port_unl: row.PORT_UNL,
cr_port_unl: row.CR_PORT_UNL,
carrier: row.CARRIER,
cnvync_id: row.CNVYNC_ID})
RETURN count(*) as total
'''
return insert_data(query, rows, batch_size)
06-23-2021 11:10 PM
Hello @jjtamer
I advice you to do the pre-treatment in Python, if you want the propery to not be created, the value must be null
so None
in your DataFrame. So replace NaN
values by None
.
Regards,
Cobra
All the sessions of the conference are now available online