Skip to content
Advertisement

How to write BigTable table data into a pandas dataframe?

I am trying to read a GCP BigTable – table to a pandas dataframe, and currently, the function I am using to fetch rows from BigTable is read_rows(), which returns PartialRowData.

Code:

from google.cloud import bigtable

client = bigtable.Client(admin=True)
instance = client.instance(bigTable_parms['instance_id'])
table = instance.table('s2')

row_data = table.read_rows()  # table.yield_rows()
for i in row_data:
    print(type(i))

Output:

<class ‘google.cloud.bigtable.row_data.PartialRowData’>

Query:

How do we read the values from PartialRowData obj?

Advertisement

Answer

There’s an example on how to call read_rows in this documentation: https://googleapis.dev/python/bigtable/latest/table.html#google.cloud.bigtable.table.Table.read_rows

for row in table.read_rows():
    # replace with your own COLUMN_FAMILY_ID and COLUMN_NAME
    cell = row.cells[COLUMN_FAMILY_ID][COLUMN_NAME][0] 
    print(cell.value.decode("utf-8"))
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement