I have a three-part question - I have three lists and I'm trying to write a loop to iterate over either two of lists to assign a value to a new column based on a match (or through the list of lists). When I assign it to the column like below it only prints the else value or whatever number in the last condition. Thank you in advance.
Why is that?
How do I format this loop?
Can someone write a better for loop that iterates over
all_namesassigning 1 to a match fromall_names[0]and 2 for a matchall_names[1]? - does enumerate work for that?first_names = ['David', 'Dani', 'Declan'] second_names = ['Katz', 'Foley', 'Stevenson'] all_names = [first_names, second_names] for row in df['name']: for elem in firstname_list: if elem in row: df['name_num']= 1 for elem in secondname_list: if elem in row: df['name_num']= 2 else: df['name_num']= 3