You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Apr 1, 2026. It is now read-only.
Create a table with Dataframe.to_gbq with clustering_columns
Reorder the clustering column and another column that has the same type
Write the updated dataframe to the same table with if_exists="replace"
Inspect the table to see columns with different data than in dataframe
Code example
importbigframes.pandasasbpdimportpandasaspdTABLE_ID="my_project.my_dataset.test_table"df=pd.DataFrame(
{"a": [10, 1, 2], "b": ["Justin", "Alex", "Jim"], "c": ["cat", "dog", "cat"]}
)
bdf=bpd.DataFrame(df)
# First time writing, all goodbdf.to_gbq(TABLE_ID, clustering_columns=["b"])
# Reorder the clustered column b and column cbdf=bdf[["a", "c", "b"]]
# When replacing and writing, the b and c columns are swappedbdf.to_gbq(TABLE_ID, if_exists="replace", clustering_columns=["b"])
While the dataframe looks good, the updated table now has columns b/c data swapped:
This doesn't happen if clustering_columns is not used in my testing.