Saturday, June 4, 2016

use a list of values to select rows from a pandas dataframe

In [5]: df = DataFrame({'A' : [5,6,3,4], 'B' : [1,2,3, 5]})

In [6]: df
Out[6]:
   A  B
0  5  1
1  6  2
2  3  3
3  4  5

In [7]: df[df['A'].isin([3, 6])]
Out[7]:
   A  B
1  6  2
2  3  3

http://www.unknownerror.org/opensource/pydata/pandas/q/stackoverflow/12096252/use-a-list-of-values-to-select-rows-from-a-pandas-dataframe

No comments:

Post a Comment