In my Azure Databricks notebook, I have defined a function fn_myFunction(...)
in the code below. But I am getting the following error:
NameError: name 'fn_myFunction' is not defined
Question: What could be a cause of the error, and how can we fix it?
import sqlalchemy as sq
import pandas as pd
pw = dbutils.secrets.get(scope='SomeScope',key='sql')
engine = sq.create_engine('mssql+pymssql://SERVICE.Databricks.NONPUBLICETL:'+pw+'MyAzureSQL.database.windows.net:1433/TEST', isolation_level="AUTOCOMMIT")
app_df = pd.read_sql('select * from MyTable', con=engine)
#create new column
app_df['NewColumn'] = app_df['TestColumn'].apply(lambda x: fn_myFunction(x))
.............
.............
def fn_myFunction(lastname):
testvar = lastname.lower()
testvar = testvar.strip()
return testvar