Q:

How to pass python dataFrame with field name as variable to user defined function

I have 2 dataframe, DataFrame1: LocationListExport - Columns: ['CountryCode', 'Country Name']
Dataframe2: Location - Columns: ['Code', 'Name']
I want to find the LocationListExport['CountryCode'] which is not present in Location['Code']
My Function:
def checkDimensionListItems(dataDL, dDLdimensionCode, knoxDimensionWithCode):
newDimensionItemAdded = dataDL[~dataDL[dDLdimensionCode].isin(knoxDimensionWithCode)][dDLdimensionCode].unique()
return newDimensionItemAdded

Calling Function:
checkDimensionListItems(LocationListExport, 'CountryCode', 'Location.Code')

Error Occurs: AttributeError: TypeError: only list-like objects are allowed to be passed to isin(), you passed a [str]
Below script works fine without function, But I want update for many dataframe.
LocationListExport[~LocationListExport.CountryCode.isin(Location.Code)].CountryCode.unique()

Can we do this using user defined function.

A:

Add 2 variable for DF & Field as below:
def checkDimensionListItems(dataDL, dDLdimensionCode, knoxDimension, knoxDimensionCode):
newDimensionItemAdded = dataDL[~dataDL[dDLdimensionCode].isin(knoxDimension[knoxDimensionCode])]

return newDimensionItemAdded

checkDimensionListItems(LocationListExport, 'Country Code', Location, 'Code')

