Reputation: 2220
I have data frame which looks like:
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
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