Python读取\u hdf,其中术语未按预期运行

2024-07-03 06:59:45 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试使用Python在HDF5格式的表上做一个简单的过滤器。仅按“主题”列进行查询时效果良好:

> df_test = pd.read_hdf(result_file, where=['subject==andrew'])
> print(df_test)

输出:

        subject condition        time  pupil_diam  luminance   gaze_x  gaze_y
 ...        ...       ...         ...         ...        ...      ...     ...
 180519  andrew     light  5885480250        2.50   0.768958  1723.85  267.11
 180520  andrew     light  5885482247        2.50   0.769088  1723.33  266.81
 180521  andrew     light  5885484249        2.51   0.769405  1718.93  267.91

当我单独通过“亮度”列进行查询时也可以使用:

> df_test = pd.read_hdf(params['result_file'], where=['luminance>0'])
> print(df_test)


        subject condition        time  pupil_diam  luminance  gaze_x  gaze_y
 79005     mary     light  3813968998        3.22   0.225418  257.11  761.28
 79006     mary     light  3813970992        3.22   0.227119  256.38  761.13
 79007     mary     light  3813972992        3.21   0.227119  256.13  760.53
 ...        ...       ...         ...         ...        ...      ...     ...

但是把这些放在一起给出一个空结果(如上所示,肯定有两个条件都为真的行):

> df_test = pd.read_hdf(params['result_file'], where=['subject==andrew & luminance>0'])
> print(df_test)

Empty DataFrame
Columns: [subject, condition, time, pupil_diam, luminance, gaze_x, gaze_y]
Index: []

尽管我使用以下命令时,此查询仍然有效:

> df_test = pd.read_hdf(params['result_file'], where=['subject==mary & luminance>0'])
> print(df_test)

       subject condition        time  pupil_diam  luminance  gaze_x  gaze_y
79005     mary     light  3813968998        3.22   0.225418  257.11  761.28
79006     mary     light  3813970992        3.22   0.227119  256.38  761.13
79007     mary     light  3813972992        3.21   0.227119  256.13  760.53
...        ...       ...         ...         ...        ...      ...     ...

对熊猫来说是新的,所以可能是我错过了一些东西。语法,但尚未在文档或在线论坛中找到合适的解决方案/解释


Tags: testdfreadresultwherefilelightpd