I have a data frame where I want to add a new column with values based on the index.
This is my fake df:
{'fruit': [
'Apple', 'Kiwi', 'Clementine', 'Kiwi', 'Banana', 'Clementine', 'Apple', 'Kiwi'],
'bites': [1, 2, 3, 1, 2, 3, 1, 2]})
I have found a similar question and tried the solution there but I get error messages. This is what I tried:
conds = [(my.index >= 0) & (my.index <= row_2),
(my.index > row_2) & (my.index<=row_5),
(my.index > row_5) & (my.index<=row_6),
(my.index > row_6)]
names = ['Donna', 'Kelly', 'Andrea','Brenda']
my['names'] = np.select(conds, names)
row_2,row_5...? what's the error message that you got?row_2 is not definedwhich makes me feel stupid since apparently that's the same question you're asking...