我无法再将数据帧写入大查询。以前这是有效的。
使用 google-cloud-bigquery 3.22.0 使用谷歌云0.34.0
import requests
import json
import pandas as pd
import google.auth
from google.cloud import bigquery
import numpy as np
def authenticate():
creds, projects = google.auth.default()
project = 'project' # Project ID inserted based on the query results selected to explore
location = 'US' # Location inserted based on the query results selected to explore
client = bigquery.Client(project=project, location=location)
return client
def update_table(table_id, data, client):
job_config = bigquery.LoadJobConfig(
create_disposition="CREATE_IF_NEEDED",
write_disposition="WRITE_TRUNCATE")
job = client.load_table_from_dataframe(
data, table_id, job_config=job_config) # Make an API request.
return job.result()
df = pd.DataFrame(np.arange(12).reshape(3, 4),
columns=['A', 'B', 'C', 'D'])
print(df)
table = ['table_name']
client = authenticate()
xx = update_table(table, df, client)
回溯(最近一次调用最后一次): 文件“c:\Users\StoneA\Documents\GitHub\UMe_almanac\df_testing.py”,第 31 行,位于 xx = update_table(表、df、客户端) 文件“c:\Users\StoneA\Documents\GitHub\UMe_almanac\df_testing.py”,第 21 行,在 update_table 中 作业= client.load_table_from_dataframe( 文件“C:\ Users \ StoneA \ AppData \ Local naconda3 nvs \ justin_model \ lib \ site-packages \ googl