I'd like help to resolve an issue I run into when I import and try to use a function that is stored in another python file. I am pretty sure it's a basic mistake I am making, and in the other Stackoverflow posts I haven't found anything similar.
The function that I have imported contains some numpy functionality. After importing it, when I call it I get the following error: "NameError: name 'np' is not defined".
Python doesn't seem to know that np represents numpy. But I have imported Numpy as np in both the file that contains the functions as well in the new Jupyter notebook where I want to use the functions. Anybody has any ideas on how to fix this?
The code of the function I am trying to import is:
def find_str_col(df):
str_col=[]
for i in range(0,df.shape[1]):
x = np.sum(df.iloc[:,i].apply(lambda x: isinstance(x,str)))
str_col.append(x)
str_col = np.squeeze(np.where(np.array(str_col)>0))
return str_col
I tried importing the function find_str_col in two ways and both ways don't work:
from Loan_price_utils import *
and also: from Loan_price_utils import find_str_col
If I do copy and paste the actual function in the new workbook it does work.