无法将数据从CoLab加载到Bigquery

时间:2020-11-12 07:11:45

标签: python pandas google-bigquery google-colaboratory

我正在尝试将5个SQL文件加载到bigquery中的5个不同的表中以可视化Data Studio中的数据。我已将这些文件上传到CoLab的存储部分并授权了该项目。

datasets = [r"/file1.sql",r"/file2.sql",,r"/file3.sql",r"/file4.sql",,r"/file5.sql"]
f = open(datasets[1], "r")
data=f.read()
data = data.replace('\n','')
import pandas as pd

df = pd.io.gbq.read_gbq('''data''', project_id='newproject1', dialect='standard')

df.head()

df.to_gbq('dataset1.testtable1','newproject1',chunksize=None,reauth=False,if_exists='append')
df.to_gbq('dataset1.testtable2','newproject1',chunksize=None,reauth=False,if_exists='append')
df.to_gbq('dataset1.testtable3','newproject1',chunksize=None,reauth=False,if_exists='append')
df.to_gbq('dataset1.testtable4','newproject1',chunksize=None,reauth=False,if_exists='append')
df.to_gbq('dataset1.testtable5','newproject1',chunksize=None,reauth=False,if_exists='append')

)

运行查询时出现以下错误。

The following traceback may be corrupted or invalid
The error message is: ('EOF in multi-line string', (1, 0))

---------------------------------------------------------------------------
BadRequest                                Traceback (most recent call last)
/usr/local/lib/python3.6/dist-packages/pandas_gbq/gbq.py in _download_results(self, query_job, max_results, progress_bar_type)
    549 
--> 550             query_job.result()
    551             # Get the table schema, so that we can list rows.

我还想知道如何更改python代码以将数据加载到5个相关的表中。

1 个答案:

答案 0 :(得分:0)

我不知道这是拼写错误还是问题所在,但请尝试替换:

function login(name, pass, server) {
    return new Promise((resolve, reject) => {

        const request = net.request({
                method: 'GET',
                url: server + '/names.nsf?Login&Username=' + name + '&Password=' + pass,
                useSessionCookies: true,
                redirect: 'follow'
            }
        )

        var first
        var second
        ///first
        request.on('response', (response) => {
        ...
            first = response.statusCode


            response.on('end', () => {
                resolve([first, second]);
            });

        })
        ///second
        request.on('redirect', (statusCode, method, redirectUrl) => {
        ...
            second = redirectUrl
        })

        request.end()

    });
}

使用

df.to_gbq(dataset1.testtable1','newproject1',chunksize=None,reauth=False,if_exists='append')
df.to_gbq(dataset1.testtable2','newproject1',chunksize=None,reauth=False,if_exists='append')
df.to_gbq(dataset1.testtable3','newproject1',chunksize=None,reauth=False,if_exists='append')
df.to_gbq(dataset1.testtable4','newproject1',chunksize=None,reauth=False,if_exists='append')
df.to_gbq(dataset1.testtable5','newproject1',chunksize=None,reauth=False,if_exists='append')