title: Filtering after Multi Indexing in pandas iterable indexing
body: <p>I want to make a subset of my dataFrame object using pandas or any other python liberary using Hierarchical indexing that can be iterable depending on number of rows I have in one of the column. </p>
  
  <pre><code>import numpy as np
  import pandas as pd
  from pandas import Series, DataFrame
  df = pd.read_csv(address)
  
      trajectory  frame   x           y                                               
  
          1       1       447,956     2,219
          1       2       447,839     2,327
          1       3       449,183     1,795
          1       4       450,444     1,833
          1       5       448,514     1,708
          1       6       451,532     1,832
          1       7       448,471     1,759
          1       8       450,028     2,097
          1       9       448,215     2,203
          1       10      449,311     2,063
          1       11      451,745     1,76
          1       12      450,827     2,264
          1       13      448,991     2,208
          1       14      452,829     3,106
          1       15      448,688     1,77
          1       16      449,844     1,951
          1       17      450,044     1,991
          1       18      449,835     1,901
          1       19      450,793     3,49
          1       20      449,618     2,354
          2       1       445.936     7.219
          2       2       442.879     3.327
          3       1       441.283     9.795
          4       1       447.956     2.219
          4       3       447.839     2.327
          4       6       449.183     1.795
  </code></pre>
  
  <p>In this DataFrame, let say there are 4 columns, names: 'trajectory', 'frame, 'x' and 'y'.  Number of 'trajectory' can be different from one dataframe to another. Each 'trajectory' can have multiple frames between 1 and 20, where they can be sequential from 1-20 or with some missing frames as well. Each frame has its own value in the column 'x' and 'y'. </p>
  
  <p>My aim is to create a new dataframe where I can have only those 'trajectory' where the 'frame' values is present for all the 20 rows. As the number of rows in 'trajectory' and 'frame' columns are changing, so I would like to have a code that can be used in such conditions.</p>
  
  <pre><code>df_1 = df.set_index(['trajectory','frame'], drop=False)
  </code></pre>
  
  <p>Here, I did a heirarchical indexing using 'trajectory' and 'frame' and then I found that 'trajectory' number 1 and 6 have 20 frames in them. So I could manually select them using the following code.</p>
  
  <pre><code>df_1_subset = df_1[(df1['traj']== 1)|(df1['trajectory']== 6)]
  </code></pre>
  
  <p>However, I have multiple csv files where in each Dataframe, the 'trajectory' that will have 20 rows in the 'frame' column will be different, so I will have to do this manually. I think, there must be a better way, but I just can not seem to find it. I am very new to coding and I would really appreciate anybody's help. Thank you very much in advance.</p>