你如何将 pytables table 读入 pandas 数据帧
how do you read a pytables table into a pandas dataframe
我构建了一个 pytables table 并使用 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()
并附加到 table:
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 中的数据。 Table.read will pull in the entire table, and Table.read_where 允许您应用条件语句来过滤返回的数据。
a = tb.open_file("FGBS.h5")
table = a.root.quote.z4
c = pd.DataFrame.from_records(table.read())
我构建了一个 pytables table 并使用 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()
并附加到 table:
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 中的数据。 Table.read will pull in the entire table, and Table.read_where 允许您应用条件语句来过滤返回的数据。
a = tb.open_file("FGBS.h5")
table = a.root.quote.z4
c = pd.DataFrame.from_records(table.read())