bar*_*man 5 python bigtable pandas pyarrow
使用案例:
我正在使用 Google BigTable 来存储这样的计数:
| rowkey | columnfamily |
| | col1 | col2 | col3 |
|----------|------|------|------|
| row1 | 1 | 2 | 3 |
| row2 | 2 | 4 | 8 |
| row3 | 3 | 3 | 3 |
Run Code Online (Sandbox Code Playgroud)
我想读取给定范围的行键的所有行(在本例中假设所有行)并聚合每列的值。
一个简单的实现将查询行并在聚合计数时迭代行,如下所示:
from google.cloud.bigtable import Client
instance = Client(project='project').instance('my-instance')
table = instance.table('mytable')
col1_sum = 0
col2_sum = 0
col3_max = 0
table.read_rows()
row_data.consume_all()
for row in row_data.rows:
col1_sum += int.from_bytes(row['columnfamily']['col1'.encode('utf-8')][0].value(), byteorder='big')
col2_sum += int.from_bytes(row['columnfamily']['col2'.encode('utf-8')][0].value(), byteorder='big')
col3_value = int.from_bytes(row['columnfamily']['col3'.encode('utf-8')][0].value(), byteorder='big')
col3_max = col3_value if col3_value > col3_max else col3_max
Run Code Online (Sandbox Code Playgroud)
问题:
有没有一种方法可以有效地将结果行加载到 pandas DataFrame 中并利用 pandas 性能进行聚合?
我想避免使用 for 循环来计算聚合,因为众所周知它的效率非常低。
我知道Apache Arrow 项目及其python 绑定,尽管 HBase 被提及为支持项目(并且 Google BigTable 被宣传为与 HBase 非常相似),但我似乎找不到一种将其用于用例的方法我在这里描述了。
我不相信 Cloud Bigtable 存在现有的 pandas 接口,但这将是一个很好的项目,类似于https://github.com/pydata/pandas-gbq中的 BigQuery 接口。
| 归档时间: |
|
| 查看次数: |
6097 次 |
| 最近记录: |