I have a Bigquery query on colab:
from google.colab import auth
auth.authenticate_user()
print('Authenticated')
project_id = '[your project ID]'
sample_count = 2000
df = pd.io.gbq.read_gbq('''
SELECT name, SUM(number) as count
FROM `bigquery-public-data.usa_names.usa_1910_2013`
WHERE state = 'TX'
AND year BETWEEN 1910 AND 1920
GROUP BY name
ORDER BY count DESC
LIMIT 100
''', project_id=project_id, dialect='standard')
df.head()
It works, but now I try to pass a parameter into the query and replace '1920' in the query WHERE clause. this parameter is dependent on another file
end_year = max(record.year) # set end_year
df = pd.io.gbq.read_gbq('''
SELECT name, SUM(number) as count
FROM `bigquery-public-data.usa_names.usa_1910_2013`
WHERE state = 'TX'
AND year BETWEEN 1910 AND end_year
GROUP BY name
ORDER BY count DESC
LIMIT 100
''', project_id=project_id, dialect='standard')
df.head()
But I get an error:
BadRequest: 400 Syntax error: Unexpected identifier "end_year"
I guess the parameter doesn't pass into the query successfully, but I don't know how to fix it.