python - How to select values from pandas dataframe by column value -


i doing analysis of dataset 6 classes, 0 based. dataset many thousands of items long.

i need 2 dataframes classes 0 & 1 first data set , 3 & 5 second.

i can 0 & 1 enough:

mnist_01 = mnist.loc[mnist['class']<= 1] 

however, not sure how classes 3 & 5... able is:

mnist_35 = mnist.loc[mnist['class'] == (3 or 5)] 

...rather doing:

mnist_3 = mnist.loc[mnist['class'] == 3] mnist_5 = mnist.loc[mnist['class'] == 5] mnist_35 = pd.concat([mnist_3,mnist_5],axis=0) 

you can use isin:

mnist = pd.dataframe({'class': [0, 1, 2, 3, 4, 5],                        'val': ['a', 'b', 'c', 'd', 'e', 'f']})  >>> mnist.loc[mnist['class'].isin([3, 5])]    class val 3      3   d 5      5   f  >>> mnist.loc[mnist['class'].isin([0, 1])]    class val 0      0   1      1   b 

Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -