Am having dataframe, I want to use apply function or lambda function for string column values in a dataframe to apply if-else conditions for columns. i have tried with for loop iterations
Input Dataframe
text1 output_column
['bread','bread','bread'] ['bread] --> [ if count values >2 ]
['bread','butter','jam'] ['butter']--> [if all 3 values are unique select 1st element value as output]
['bread','jam','jam'] ['jam']--> [if count values >2]
['unknown'] ['unknown'] --> [if any of the value came as blank or null mark it as 'unknown']
################## I tried below lines of code#########
output_column=[]
df_value = df[['text_col1','text_col2','text_col3']].values.tolist()
if np.all(df_value <= 1):
output_column.append(df_value[1])
else:
output_column.append(max_count[np.argmax(df_value)])
output Dataframe
text1 output_column
['bread','bread','bread'] ['bread']
['bread','butter','jam'] ['butter']
['bread','jam','jam'] ['jam']
['unknown'] ['unknown']