user2293224
user2293224

Reputation: 2220

Python: "'float' object has no attribute 'isin'" when comparing columns

I have data frame which looks like:

enter image description here

Now I am comparing whether two columns (i.e. complaint and compliment) have equal value or not: I have written a function:

def col_comp(x):
    return x['Complaint'].isin(x['Compliment'])

When I apply this function to dataframe i.e.

df.apply(col_comp,axis=1)

I get an error message

AttributeError: ("'float' object has no attribute 'isin'", 'occurred at index 0')

Any suggestion where I am making the mistake.

Upvotes: 0

Views: 2243

Answers (1)

busybear
busybear

Reputation: 10590

isin requires an iterable. You are providing individual data points (floats) with apply and col_comp. What you should use is == in your function col_comp, instead of isin. Even better, you can compare the columns in one call:

df['Complaint'] == df['Compliment']

Upvotes: 4

Related Questions