Pandas HD5查询,其中表达式失败

use*_*418 7 python-2.7 pandas

我想查询HDF5文件.我做

df.to_hdf(pfad,'df', format='table')
Run Code Online (Sandbox Code Playgroud)

在光盘上写入数据帧.

阅读我用

hdf = pandas.HDFStore(pfad)
Run Code Online (Sandbox Code Playgroud)

我有一个包含numpy.datetime64称为expirations的值的列表,并尝试将hd5表的一部分读入数据帧,该数据帧具有列之间expirations[1]expirations[0]列之间的值"expiration".列到期条目具有格式Timestamp('2002-05-18 00:00:00').

我使用以下命令:

df = hdf.select('df',
                where=['expiration<expiration[1]','expiration>=expirations[0]'])
Run Code Online (Sandbox Code Playgroud)

但是,这会失败并产生值错误:

ValueError: The passed where expression: [expiration=expirations[0]]
            contains an invalid variable reference
            all of the variable refrences must be a reference to
            an axis (e.g. 'index' or 'columns'), or a data_column
            The currently defined references are: index,columns

Lor*_*tti 0

你能试试这段代码吗:

df = hdf.select('df', where='expiration < expirations[1] and expiration >= expirations[0]')
Run Code Online (Sandbox Code Playgroud)

或者,作为查询:

df = hdf.query('expiration < @expirations[1] and expiration >= @expirations[0]')
Run Code Online (Sandbox Code Playgroud)

不确定哪一个最适合您的情况,我注意到您正在尝试使用“where”来过滤行,没有字符串或列表,这有意义吗?