1

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.

1
  • Looks quite simple but this would be much easier if you shared sample code with us, e.g. df.head().to_dict() Commented Jul 30, 2017 at 13:31

1 Answer 1

1

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')

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.