My code is:
def load_data(datafile, categories=None, cat_columns=None):
ohe_categories = 'auto'
if categories and len(categories) > 0:
ohe_categories = categories
ohe = OneHotEncoder(handle_unknown='ignore', categories=ohe_categories)
When categories is None, it works fine. But if I pass something, I get an error:
ValueError: The truth value of a Index is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
I am calling the function with:
training_x, training_y, categories, cat_columns = loader.load_data(
'data/training.csv')
test_x, test_y = loader.load_data(
'data/test.csv', categories=categories, cat_columns=cat_columns)
How can I check properly?
IndexIndexwhich does not behave like you expect forif categories.... Tryif categories != None and ...