I have a dictionary wrong_names
, a pandas series df['name']
, and an empty list i_list
.
I want to iterate through df['name']
, and if the name is in wrong_names.keys()
, I want to append the index of that element in df
to i_list
. Here is what I have so far:
i_list = []
for pup in df['name']:
if pup in wrong_names.keys():
i_list.append(df.index.get_loc(pup))
i_list
I have already looked at .get_loc documentation (is pup the right argument?), as well as these S.O. questions:
Finding label location in a DataFrame Index
Find element's index in pandas Series
The code works fine when all I ask it to do is append pup
to i_list
, by all indications the loop correctly identifies when the pup
is also a key in the dictionary,
i_list = []
for pup in df['name']:
if pup in wrong_names.keys():
i_list.append(pup)
i_list
but I can't get a list of the indices, which is what I need for the next step. Thanks in advance.