I am trying to assign name to a cluster basis on the some comparative conditions, however i am getting error stating as numpy float object not iterable. Besides i don't wish to subset the dataset as you can see below from df to df1 and later concat it. Below is the code:
import pandas as pd
df = pd.DataFrame({'cluster':[0, 1, 2, 9999], 'earlypc':[88.943,4.034,6.839,0.488],'C':[3.491,8.306,75.329,34.5],'D':[14.548,87.66,17.832,65.012]})
df1=df[df['cluster']!=999]
def cluster(a,b,c,d):
if(max(b)==b):
return 'high'
elif (max(c)==c):
return 'low'
elif (max(d)==d):
return 'medium'
else: return 'medium'
df1['Vendor_Segmentation']=df1.apply(lambda x:cluster(x['cluster'],x['earlypc'],x['C'],x['D']),axis=1)
TypeError: 'numpy.float64' object is not iterable