using pandas in Python2-7 I have the following dataframe (dfmain):
Col1 Letter
0 One A
1 Two B
2 Three C
3 Four A
4 Five D
5 Six B
6 Seven C
I'd like to filter out all rows with 'C' or 'D' as a letter or alternatively only rows 'A' and 'B'. The following code works for only one letter:
dftemp = dfmain[dfmain['Letter'] == 'A']
or alternatively:
dftemp = dfmain[dfmain['Letter'] != 'D']
However, how would I do this for more than one letter, e.g. I've tried:
dftemp = dfmain[dfmain['Letter'] == 'A', 'B']
or:
dftemp = dfmain[dfmain['Letter'] == ['A','B']]
and a few other ways but these produce errors. Any ideas?