pandasdataframetimestampbooleanbooleanquery

How to modulo query on pandas


I need modulo query because the data is to long and need to show in one screen only. Here's my dataset

     Name
1    they
2    ulti
3    they
4    set
5    djhd
6    tdh
7    t473

What I need is, 1 modulo 3 in this case

     Name
1    they
4    set
7    t473

Solution

  • Use boolean indexing with modulo 3:

    df = df[df.index % 3 == 1]
    print (df)
       Name
    1  they
    4   set
    7  t473
    

    Detail:

    print (df.index % 3 )
    Int64Index([1, 2, 0, 1, 2, 0, 1], dtype='int64')