简体   繁体   English

GCP 环境中相同 %%bigquery 命令的 Jupyter 实验室语法错误

[英]Jupyter lab syntax error for the same %%bigquery command on the GCP environment

I am trying to fetch a BigQuery table as a Python dataframe in the GCP's Jupyter lab environment.我正在尝试在 GCP 的 Jupyter 实验室环境中将 BigQuery 表作为 Python dataframe 获取。 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.工作得很好,也对 dataframe 进行了分析。但是,在重新启动 kernel 后,我无法从同一命令重新创建 df The following is the error I received.以下是我收到的错误

# Loading data from BigQuery to Python as 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 示例数据集上打开一个新笔记本来运行相同的步骤,令我惊讶的是,它运行良好。

%%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.不幸的是,我不知道如何在 GCP 平台上共享可重现的代码,因为我是新手。 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.敲了4个多小时的脑袋,报错的原因很简单。 Comments preceding the %%bigquery magic command are not allowed.不允许在 %%bigquery 魔法命令之前添加注释。 Remove those comments and re-run the code block.删除这些注释并重新运行代码块。

The original answer was found in this thread .原来的答案是在这个线程中找到的。 It was great learning.这是很好的学习。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM