【问题标题】:How to modulo query on pandas如何对熊猫进行模查询
【发布时间】:2023-03-21 14:03:01
【问题描述】:

我需要模数查询,因为数据很长,只需要在一个屏幕上显示。这是我的数据集

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

我需要的是 1 modulo 3 在这种情况下

     Name
1    they
4    set
7    t473

【问题讨论】:

    标签: pandas dataframe timestamp boolean booleanquery


    【解决方案1】:

    boolean indexing 与模 3 一起使用:

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

    详情

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-10-13
      • 2022-12-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-09-09
      • 1970-01-01
      • 2012-08-21
      相关资源
      最近更新 更多