Category : for-loop

I have ten datasets which I have split into training and test sets: names=["df1","df2","df3", "df4", "df5", "df6", "df7", "df8", "df9", "df10"] dataset_list = [] for i in range(len(names)): datasets = pd.read_csv(f"{fulldatafolder}/"+names[i]+"_Full_Dataset.csv") dataset_list.append(datasets) training_set_list=list() test_set_list=list() for dataset in dataset_list: training_sets, test_sets=np.split(dataset, [int(.90*len(dataset))]) training_set_list.append(training_sets) test_set_list.append(test_sets) However, if I try to save all these datasets to their respective ..

Read more

I don’t understand where I am wrong. I will post the assignment and my script down below. # Loop through the letters of the variable `summer_word` from above. # Concatenate the consonants from `summer_word` and answer with the new word. # # Tip: Create a string that contains consonants and check if each letter is ..

Read more

I was asked to find common items between two lists in Python during an interview. I provided three solutions: using set.intersection, list comprehension and for loop. Below is the for loop I did: def common_elements(list1, list2): result = [] for element in list1: if element in list2: result.append(element) return result After I did the for ..

Read more