I'm trying to apply a condition to a column in my pandas dataframe, but i get this error :
TypeError: 'float' object is not iterable
Cars = {'Brand': ['Honda Civic','Toyota Corolla','Ford Focus','Audi A4'],
'Price': [22.000,25.000,27.000,35.000]
}
Cars = DataFrame(Cars, columns= ['Brand', 'Price'])
Cars ['Price'] = Cars ['Price'].apply(lambda x: [0 if y <= 25.000 else 1 for y in x])
Any thoughts ?
apply, the argument to the function is a single element of the container. In other words, instead oflambda x: [0 if y <= 25.000 else 1 for y in x], you just wantlambda x: 0 if x <= 25.000 else 1.