首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >你是如何把一张比目表读成熊猫数据的?

你是如何把一张比目表读成熊猫数据的?
EN

Stack Overflow用户
提问于 2015-01-13 09:39:41
回答 1查看 2.2K关注 0票数 1

我已经构建了一个pytable表,并使用附件填充了它,如下所示:

代码语言:javascript
复制
h5file = open_file("FGBS.h5", mode = "a")
group = h5file.create_group("/", 'hybrid')
table = h5file.create_table(group, 'z4', Hybrid ,filters= tb.Filters(5, "blosc"))

使用:

代码语言:javascript
复制
class Hybrid(IsDescription):
    dateTime = Time32Col()
    price = Float64Col()
    quantity = Float64Col()
    bidPrc = Float64Col()
    bidSize = Float64Col()
    askPrc = Float64Col()
    askSize = Float64Col()

并附在表上:

代码语言:javascript
复制
           if 0 in dictInstrumentsData[message.symbol].bidPrice and 0 in dictInstrumentsData[message.symbol].askPrice:
                hybrid = table.row
                hybrid["dateTime"] = message.timestamp * 0.001
                hybrid["price"] = message.price
                hybrid["quantity"] = message.size
                hybrid["bidPrc"] = dictInstrumentsData[message.symbol].bidPrice[0]
                hybrid["bidSize"] = dictInstrumentsData[message.symbol].bidSize[0]
                hybrid["askPrc"] = dictInstrumentsData[message.symbol].askPrice[0]
                hybrid["askSize"] = dictInstrumentsData[message.symbol].askSize[0]

                hybrid.append()

现在我正试着把它读回一只熊猫的数据,就像这样:

代码语言:javascript
复制
a = tb.open_file("FGBS.h5")
table = a.root.quote.z4
c = pd.DataFrame.from_records(table)

但是当我看c的时候,我得到的只是:

代码语言:javascript
复制
                                          0       \
0  /hybrid/z4.row (Row), pointing to row #164411   

                                          1       \
0  /hybrid/z4.row (Row), pointing to row #164411   

                                          2       \
0  /hybrid/z4.row (Row), pointing to row #164411   

                                          3       \
0  /hybrid/z4.row (Row), pointing to row #164411   

                                          4       \
0  /hybrid/z4.row (Row), pointing to row #164411   

                                          5       \
0  /hybrid/z4.row (Row), pointing to row #164411   

                                          6       \
0  /hybrid/z4.row (Row), pointing to row #164411   

                                          7       \
0  /hybrid/z4.row (Row), pointing to row #164411   

                                          8       \
0  /hybrid/z4.row (Row), pointing to row #164411   

                                          9       \
0  /hybrid/z4.row (Row), pointing to row #164411   

                       ...                        \
0                      ...                         

                                          164401  \
0  /hybrid/z4.row (Row), pointing to row #164411   

                                          164402  \
0  /hybrid/z4.row (Row), pointing to row #164411   

                                          164403  \
0  /hybrid/z4.row (Row), pointing to row #164411   

                                          164404  \
0  /hybrid/z4.row (Row), pointing to row #164411   

                                          164405  \
0  /hybrid/z4.row (Row), pointing to row #164411   

                                          164406  \
0  /hybrid/z4.row (Row), pointing to row #164411   

                                          164407  \
0  /hybrid/z4.row (Row), pointing to row #164411   

                                          164408  \
0  /hybrid/z4.row (Row), pointing to row #164411   

                                          164409  \
0  /hybrid/z4.row (Row), pointing to row #164411   

                                          164410  
0  /hybrid/z4.row (Row), pointing to row #164411  

[1 rows x 164411 columns]

不是基于每个附加的混合列和行的数据文件。有人能帮我看看我做错了什么吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-01-13 10:06:38

您需要从表中显式读取数据。Table.read将提取整个表,哪里允许您应用一个条件语句来筛选返回的数据。

代码语言:javascript
复制
a = tb.open_file("FGBS.h5")
table = a.root.quote.z4
c = pd.DataFrame.from_records(table.read())
票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/27918990

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档