提问人:user3276418 提问时间:11/27/2014 最后编辑:filmoruser3276418 更新时间:1/3/2023 访问量:1416
Pandas HD5 查询,表达式失败
Pandas HD5-query, where expression fails
问:
我想查询一个 HDF5 文件。我愿意
df.to_hdf(pfad,'df', format='table')
将 DataFrame 写入磁盘。
阅读我使用
hdf = pandas.HDFStore(pfad)
我有一个列表,其中包含称为过期的值,并尝试将 hd5 表的部分读取到数据帧中,该数据帧的值介于列之间和列中。列过期条目的格式为 。numpy.datetime64
expirations[1]
expirations[0]
"expiration"
Timestamp('2002-05-18 00:00:00')
我使用以下命令:
df = hdf.select('df',
where=['expiration<expiration[1]','expiration>=expirations[0]'])
但是,此操作将失败并产生值错误:
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
答:
0赞
Lorenzo Bassetti
1/3/2023
#1
你能试试这个代码吗?
df = hdf.select('df', where='expiration < expirations[1] and expiration >= expirations[0]')
或者,作为查询:
df = hdf.query('expiration < @expirations[1] and expiration >= @expirations[0]')
不确定哪一个最适合您的情况,我注意到您正在尝试使用“where”来过滤行,没有字符串或列表,这有意义吗?
评论