簡體   English   中英

你如何將pytables表讀入pandas數據幀

[英]how do you read a pytables table into a pandas dataframe

我已經構建了一個pytables表並使用append填充它:

h5file = open_file("FGBS.h5", mode = "a")
group = h5file.create_group("/", 'hybrid')
table = h5file.create_table(group, 'z4', Hybrid ,filters= tb.Filters(5, "blosc"))

使用:

class Hybrid(IsDescription):
    dateTime = Time32Col()
    price = Float64Col()
    quantity = Float64Col()
    bidPrc = Float64Col()
    bidSize = Float64Col()
    askPrc = Float64Col()
    askSize = Float64Col()

並附在表格旁邊:

           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()

現在我想把它讀回到像這樣的pandas數據幀:

a = tb.open_file("FGBS.h5")
table = a.root.quote.z4
c = pd.DataFrame.from_records(table)

但是當我看到c時,我得到的是:

                                          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]

不是具有基於每個追加的混合列和行的列的數據框。 任何人都可以幫我告訴我我做錯了什么

您需要顯式讀取表中的數據。 Table.read引入整個表, Table.read_where允許您應用條件語句來過濾返回的數據。

a = tb.open_file("FGBS.h5")
table = a.root.quote.z4
c = pd.DataFrame.from_records(table.read())

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM