I am trying to fetch a BigQuery table as a Python dataframe in the GCP's Jupyter lab environment. It worked perfectly fine and also performed analysis on the dataframe. However, after restarting the kernel, I am unable to recreate the df from the same command. The following is the error I received.
# Loading data from BigQuery to Python as a dataframe
%%bigquery input
SELECT
*
FROM dataset.table1
Error:
File "/tmp/ipykernel_26547/1617235092.py", line 4
SELECT *
^
SyntaxError: invalid syntax
Alternatively, I tried to run the same step by opening a new notebook on a BigQuery sample dataset and to my surprise, it worked perfectly.
%%bigquery input
SELECT
*
FROM `bigquery-public-data.samples.natality`
LIMIT 5
Unfortunately, I am unaware of how to share a reproducible code on the GCP platform, as I am fairly new. But, I would love to hear your views and understand the cause of the issue/error.
After banging my head for more than 4 hours, the reason for the error was simple. Comments preceding the %%bigquery magic command are not allowed. Remove those comments and re-run the code block.
The original answer was found in this thread. It was great learning.