Pandas/BigQuery-TypeError:'<';在';str';和';int';
我试图将panda中的数据加载到BigQuery中,但遇到以下错误: 回溯(最近一次呼叫最后一次): 文件“pandas\libs\index.pyx”,第112行,在pandas.\u libs.index.IndexEngine.\u获取\u loc\u副本Pandas/BigQuery-TypeError:'<';在';str';和';int';,pandas,google-bigquery,Pandas,Google Bigquery,我试图将panda中的数据加载到BigQuery中,但遇到以下错误: 回溯(最近一次呼叫最后一次): 文件“pandas\libs\index.pyx”,第112行,在pandas.\u libs.index.IndexEngine.\u获取\u loc\u副本 TypeError:“看看错误回溯,有一行箭头指向错误语句,它似乎来自我刚刚导入的pandas文件,而不是通过我编写的任何代码。改变这些是正常的吗?有时可能是“间接的”“由代码生成的扩展代码导致的错误。因此,要跟踪代码,请使用箭头检查回
TypeError:“看看错误回溯,有一行箭头指向错误语句,它似乎来自我刚刚导入的pandas文件,而不是通过我编写的任何代码。改变这些是正常的吗?有时可能是“间接的”“由代码生成的扩展代码导致的错误。因此,要跟踪代码,请使用箭头检查回溯。通常位于回溯的顶部。我有点不确定如何执行此操作-我应该查看哪个文件?错误消息类似于:
AttributeError:'dict_items'对象没有属性“值”--------------------------------------------------------------------------------------AttributeError回溯(最近一次调用last)在--->1 dict(d.items().values())AttributeError:“dict_items”对象没有属性“values”
中,您只需查看-->
就可以了解哪一行代码出现错误。
x = response['rows']
df = pd.DataFrame.from_dict(x)
# split the keys list into columns
df[['query','device', 'page', 'date']] = pd.DataFrame(df['keys'].values.tolist(), index= df.index)
# Drop the key columns
result = df.drop(['keys'],axis=1)
# Add a website identifier
result['website'] = site_url
result['country'] = "gbr"
result['ctr'] = 1.5
column_names = ["date", "query", "page", "clicks", "impressions", "ctr", "position", "website", "country", "device", "website"]
result = result.reindex(columns=column_names)
print(result.dtypes)
print(result)
# establish a BigQuery client
client = bigquery.Client.from_service_account_json(SERVICE_ACCOUNT_FILE)
dataset_id = BQ_DATASET_NAME
table_name = BQ_TABLE_NAME
# create a job config
job_config = bigquery.LoadJobConfig()
# Set the destination table
table_ref = client.dataset(dataset_id).table(table_name)
job_config.write_disposition = 'WRITE_APPEND'
load_job = client.load_table_from_dataframe(result, table_ref, job_config=job_config)
load_job.result()