How to fix 'NameError' name 'xxx' is not defined
Hi,
While running a python recipe for generating 2 output datasets, getting an error :
<class 'NameError'>: name 'ptk_ddd_df' is not defined
in #Write recipe outputs, in this line ptk_ddd.write_with_schema(ptk_ddd_df):
# Write recipe outputs
ptk_ddd = dataiku.Dataset("PTK_DDD")
ptk_ddd.write_with_schema(ptk_ddd_df)
dtd_ptk = dataiku.Dataset("DTD_PTK")
dtd_ptk.write_with_schema(dtd_ptk_df)
Kindly suggest.
Thanks,
Parul.
(Topic title edited by moderator to be more descriptive. Original title "Using Dataiku")
Answers
-
Hello,
That error is thrown by the Python interpreter, letting you know that ptk_ddd_df has not been previously defined before using it. You are supposed to implement the logic in Python that populates a Pandas dataframe (the variable you are missing, in this case) that is then written to the dataset. This is what the boilerplate code looks like for a Python recipe writing to two output datasets (a and b) should look like:
# -*- coding: utf-8 -*- import dataiku import pandas as pd, numpy as np from dataiku import pandasutils as pdu # Compute recipe outputs # TODO: Write here your actual code that computes the outputs # NB: DSS supports several kinds of APIs for reading and writing data. Please see doc. # It is up to you to implement the logic below that will create pandas dataframes (a_df and b_df) that will then be written to the dataset a_df = ... # Compute a Pandas dataframe to write into a b_df = ... # Compute a Pandas dataframe to write into b # Write recipe outputs a = dataiku.Dataset("a") a.write_with_schema(a_df) b = dataiku.Dataset("b") b.write_with_schema(b_df)
I hope that clarifies it. If you still need help, please share your entire recipe code so that we can inspect it.
-
Hi,
Thanks for the clarity.
-Parul.