0

So I have a DataFrame called trials, and a series of logical values called random. random is a logical series the same length as the number of rows in each columns in trials.

 trials.shape
Out[72]: (199, 4)

random.value_counts()
Out[74]: 
False    192
True       7
dtype: int64

I used the following solution to get the rows of all the columns in trials but it is not scalable, what if I have more columns than this is feasible for or if I want to simultaneously filter for columns and rows?

trials[['Choice','LeftContrast','RightContrast','feedback']][random]
Out[67]: 
    Choice LeftContrast RightContrast feedback
16   [1.0]       [0.25]        [0.25]    [1.0]
25   [1.0]        [1.0]         [1.0]    [1.0]
79   [1.0]        [1.0]         [1.0]   [-1.0]
80   [1.0]        [1.0]         [1.0]   [-1.0]
93   [1.0]        [1.0]         [1.0]    [1.0]
122  [1.0]        [0.5]         [0.5]   [-1.0]
166  [0.0]       [0.25]        [0.25]   [-1.0]

How could I write this so that I don't have to specify all the columns I want compared? Calling ":" creates an error:

trials[[:]][random]
  File "<ipython-input-68-a82ea1b0ab14>", line 1
    trials[[:]][random]
            ^
SyntaxError: invalid syntax

Using .iloc also produces an error.

trials.iloc[random,:]
Traceback (most recent call last):

What if I wanted to use logicals to assess both rows and columns?

Henry Ecker
  • 34,399
  • 18
  • 41
  • 57
Angus Campbell
  • 563
  • 4
  • 19

0 Answers0