是否可以使用'read_hdf'函数的'where'参数选择仅写到HDF5文件的熊猫数据帧中行的子集?
例如:
import pandas as pd, os
t = pd.DataFrame(data={'i1':['AA','AB','BA','BB'],
'i2':[0,1,2,3],
'x':[0.,2.,2.,3.]})
t.set_index(['i1','i2'], inplace=True)
t.sort_index(inplace=True)
path = os.path.join(os.environ['HOME'], 'temp/temp.h5')
t.to_hdf(path, 't', format='table')
# attempt to select rows where 'i1' ends with "A"
t2 = pd.read_hdf(path, where='i1[-1:]=="A"')
t2 = pd.read_hdf(path, where='i1=="*A"')
我猜想该解决方案会以某种有效的PyTables Expr作为“ where”。
谢谢您的帮助!