Imagine I have a list that represents the indexes of a dataframe, like this one:
indexlist = [0,1,4]
And the following dataframe:
Name Country
0 John BR
1 Peter BR
2 Paul BR
3 James CZ
4 Jonatan CZ
5 Maria DK
I need to create a column on this dataframe named "Is it valid?" that would add "Yes" if the index row is in the list. Otherwise would add "No", resulting in this dataframe:
Name Country Is it valid?
0 John BR Yes
1 Peter BR Yes
2 Paul BR No
3 James CZ No
4 Jonatan CZ Yes
5 Maria DK No
Is there any way I could do it?
Thanks!
df['Is it valid?'] = df.index.isin(indexlist)