我用for循环覆盖满了光栅的列表。对于每个光栅,我提取一个数据数组,并希望使用光栅的基名称(日期)作为该数组的索引。为此,我使用熊猫数据帧多索引。然后,包含新集合索引的数组被追加到HDFStore。接下来,将选择另一个日期的光栅
代码段:
root, ext = os.path.splitext(raster)
name = int(decimal.Decimal(os.path.basename(root)))
array = ma.MaskedArray.compressed(raster)
arr2df = pd.DataFrame(pd.Series(data = array), columns=['rastervalue'])
arr2df['timestamp'] = pd.Series(name,index=arr2df.index)
arr2df.set_index('timestamp')
store.append('rastervalue',arr2df)
DataFrame似乎没问题(顺便说一句,我如何检索多重索引?)。在
^{pr2}$但在我检查HDFStore时,我的多重索引似乎消失了,变成了“values_block_1”
>>> store.root.rastervalue.table.read
<bound method Table.read of /rastervalue/table (Table(12626172,)) ''
description := {
"index": Int64Col(shape=(), dflt=0, pos=0),
"values_block_0": Int32Col(shape=(1,), dflt=0, pos=1),
"values_block_1": Int64Col(shape=(1,), dflt=0, pos=2)}
byteorder := 'little'
chunkshape := (3276,)
autoIndex := True
colindexes := {
"index": Index(6, medium, shuffle, zlib(1)).is_CSI=False}>
>>> store.root.rastervalue.table.read(field="values_block_1")
array([[20060101],
[20060101],
[20060101],
...,
[ 20060914],
[ 20060914],
[ 20060914]], dtype=int64)
通过阅读documentation我不知道如何正确地在HDFStore中存储或更改多重索引。有什么建议吗?最后,我想将该表查询为:
store.select('rastervalue', [ pd.Term('index', '=', '20060101')])
这是一个有效的例子。在
相关问题 更多 >
编程相关推荐