【问题标题】:In Qgrid, is there a way to apply a default row filter when displaying the table在Qgrid中,有没有办法在显示表格时应用默认行过滤器
【发布时间】:2019-11-07 00:36:30
【问题描述】:

我在文档中找不到显示与我的预过滤数据框关联的 qgrid 表的方法

想象一下我有一个像这样的数据框:

df_types = pd.DataFrame({
'A' : 1.,
'B' : pd.Series(['2013-01-01', '2013-01-02', '2013-01-03', '2013-01-04',
           '2013-01-05', '2013-01-06', '2013-01-07', '2013-01-08', '2013-01-09'],index=list(range(9)),dtype='datetime64[ns]'),
'C' : pd.Series(randn(9),index=list(range(9)),dtype='float32'),
'D' : np.array([3] * 9,dtype='int32'),
'E' : pd.Categorical(["washington", "adams", "washington", "madison", "lincoln","jefferson", "hamilton", "roosevelt", "kennedy"]),
'F' : ["foo", "bar", "buzz", "bippity","boppity", "foo", "foo", "bar", "zoo"] })

最初在显示表格时,我只想显示列“F”等于foobar的行,而不是全部(但仍然可以在 qgrid 标题中选择其他行)

【问题讨论】:

    标签: python jupyter-notebook qgrid


    【解决方案1】:

    在 qgrid github 上阅读了一些测试文件后。下面的代码可能会有所帮助。但是,与单击过滤器相比,可见行看起来不同。

    qw = qgrid.show_grid(df_types, show_toolbar=True)
    qw._handle_qgrid_msg_helper({
            'type': 'show_filter_dropdown',
            'field': 'F',
            'search_val': 'bar'
        })
    qw._handle_qgrid_msg_helper({
            'field': "F",
            'filter_info': {
                'field': "F",
                'selected': [0],
                'type': "text",
                'excluded': []
            },
            'type': "change_filter"
        })
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-03-08
      • 2020-09-16
      相关资源
      最近更新 更多