我的问题是关于在Google数据实验室中尝试此操作,但不断返回语法错误
File "<ipython-input-26-03f6ca240d16>", line 4
WITH trips AS (
^
SyntaxError: invalid syntax
import google.datalab.bigquery as bq
import pandas as pd
import numpy as np
import shutil
%bq query -n taxiquery
WITH trips AS (
SELECT EXTRACT (DAYOFYEAR from pickup_datetime) AS daynumber
FROM `bigquery-public-data.new_york.tlc_yellow_trips_*`
where _TABLE_SUFFIX = @YEAR
)
SELECT daynumber, COUNT(1) AS numtrips FROM trips
GROUP BY daynumber ORDER BY daynumber
query_parameters = [
{
'name': 'YEAR',
'parameterType': {'type': 'STRING'},
'parameterValue': {'value': 2015}
}
]
trips = taxiquery.execute(query_params=query_parameters).result().to_dataframe()
trips[:5]
答案 0 :(得分:1)
将查询定义输出到自己的单元格中。 %bq query...
是一种多线魔术语法,需要单独存在于单元格中。