У меня есть DataFrame, а именно 'traj', как показано ниже:
x y z
0 5 3 4
1 4 2 8
2 1 1 7
3 Some string here
4 This is spam
5 5 7 8
6 9 9 7
... #continues repeatedly a lot with the same strings here in index 3 and 4
79 4 3 3
80 Some string here
Я определяю функцию для удаления бесполезных строк, расположенных в определенном индексе, из DataFrame. Вот то, что я пытаюсь:
def spam(names,df): #names is a list composed, for instance, by "Some" and "This" in 'traj'
return df.drop(index = ([traj[(traj.iloc[:,0] == n)].index for n in names]))
Но когда я вызываю его, он возвращает ошибку:
traj_clean = spam(my_list_of_names, traj)
...
KeyError: '[(3,4,...80)] not found in axis'
Если я попытаюсь один:
traj.drop(index = ([traj[(traj.iloc[:,0] == 'Some')].index for n in names]))
это работает.