There is a module in helpers directory called helper_a.py. It has all classes and functions defined here.
Now I want to call a function from here into another module (not in helpers directory) but one step (cd ..) behind. (init.py) is in helpers directory.
Code and error is as below :
from helpers.helper_a import *
import pandas as pd
query_train_data = "select * from train;"
df_train_dataset = pd.read_sql(query_train_data, con=engDps1000)
query_test_data = "select * from test;"
df_test_dataset = pd.read_sql(query_test_data, con=engDps1000)
df_train_data = df_train_dataset
df_test_data = df_test_dataset
data_prep_steps() # This function is defined in helpers_a
Error:
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
<ipython-input-12-3c88b46f341a> in <module>
----> 1 data_prep_steps()
~\Desktop\Notebooks\helpers\helper_a.py in data_prep_steps()
---> 89 # STEP 1 : CONVERT REQUIRED COLS TO CATEGORIES
90 for df_name in [df_train_data, df_test_data]:
91 data_prep_class = data_prep(df_name)
NameError: name 'df_train_data' is not defined
Question is that the variable df_train data is defined in the current module and i want to use it in the function defined in helpers_a by calling it also in the current module, but why is it not recognizing this variable??
Note : Also tried assigning global variable status but it still doesnt solve the issue
df_train_dataanddf_test_dataintodata_prep_steps(), why don't you pass these 2 variables as arguments ? -- I think you should try to make a minimal reproducible example, the questions will be more easily answered this way, and by reproducing your example, you might find the answer yourself.