0

My question is about Trying this in Google Data lab, but keeps returning a syntax error

  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]
aL_eX
  • 1,453
  • 2
  • 15
  • 30

1 Answers1

1

Take the query definition out into its own cell. The %bq query... is a multiline magic syntax that needs to be in a cell on its own.

yelsayed
  • 5,236
  • 3
  • 27
  • 38