TypeError to_gbq() 得到了一个意外的关键字参数 'location'

TypeError to_gbq() got an unexpected keyword argument 'location'

我正在使用 Google Colaboratory 创建一个 table 以上传到 Google BigQuery。我的笔记本在尝试将数据上传到 BigQuery 时收到 TypeError: to_gbq() got an unexpected keyword argument 'location'。下面是抛出错误的代码。


    from google.colab import files
    from google.colab import drive
    from google.colab import auth
    from oauth2client.client import GoogleCredentials
    drive.mount('/content/gdrive')

    Drive already mounted at /content/gdrive; to attempt to forcibly remount, call drive.mount("/content/gdrive", force_remount=True).

    import pandas as pd
    import io
    import numpy as np
    import matplotlib.pyplot as plt
    %matplotlib inline

    ## Usage file
    df = pd.read_csv("/content/gdrive/My Drive/test.csv")
    df.info()
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 3 entries, 0 to 2
Data columns (total 4 columns):
Header1     3 non-null object
Header2     3 non-null object
    Header3    3 non-null object
Header4     3 non-null object
dtypes: object(4)
memory usage: 176.0+ bytes

    df.to_gbq('table.new', 'tableproject-196326', if_exists='replace')

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-4-efe83f801834> in <module>()
----> 1 df.to_gbq('table.new', 'tableproject-196326', if_exists='replace')

1 frames
/usr/local/lib/python3.6/dist-packages/pandas/io/gbq.py in to_gbq(dataframe, destination_table, project_id, chunksize, reauth, if_exists, auth_local_webserver, table_schema, location, progress_bar, credentials, verbose, private_key)
    160         auth_local_webserver=auth_local_webserver, table_schema=table_schema,
    161         location=location, progress_bar=progress_bar,
--> 162         credentials=credentials, verbose=verbose, private_key=private_key)

    TypeError: to_gbq() got an unexpected keyword argument 'location'

    df.head()

这个错误刚刚开始出现。

有关如何解决此问题的任何帮助。

尝试使用 pandas_gbq 并从 google.oauth2 导入 service_account。以下代码在 Colaboratory 中对我有用。

from google.oauth2 import service_account
import pandas_gbq as gbq
gbq.to_gbq(df, 'test_dataset.test_table', 'add_project_id', if_exists='append')