跳到正文
Skillpedia
分析与电子表格22k · #10226

bigquery-bigframes

它能做什么

这个技能帮你用熟悉的 Python 代码分析 BigQuery 数据。它适用于更喜欢 Python 而非 SQL,并希望在 BigQuery 内完成大规模数据工作的人。

适用场景

  • ✓当你想用熟悉的 Python 代码分析或转换 BigQuery 数据的时候。
  • ✓当你在 BigQuery 的数据上用 Python 构建机器学习流程的时候。
  • ✓当你需要预览或清理大型 BigQuery 数据集,又不想下载它的时候。

技能链接

https://github.com/google/skills/blob/main/skills/cloud/bigquery-bigframes/SKILL.md

复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。

使用方法

最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。

可直接粘贴的消息

请用这个技能帮我:https://github.com/google/skills/blob/main/skills/cloud/bigquery-bigframes/SKILL.md 阅读该链接中的 SKILL.md 文件,并在我的任务中按照它的说明来做。
想让你的 AI 自己找到这样的技能吗?安装免费的 Skillpedia MCP:只需一行,每次任务前它都会在 15,000+ 个技能中搜索。1 分钟完成安装 →

可以这样问 AI

“请写一段 Python 代码清理一个大型 BigQuery 表,并给我预览,不要下载整个表。”

每周 5 个新技能,1 分钟读完。

工作原理

它使用 BigFrames 这个类似 pandas 风格的 Python 库,让数据处理在 BigQuery 内运行。它还会推荐一些能让工作保持快速的设置和预览方法。

技术内容(原始 SKILL.md)

作者在 GitHub 上的英文原文。

BigFrames (BigQuery DataFrame) basics

BigFrames is a Python library that lets you take advantage of BigQuery data processing by using familiar Python APIs.

Attribution

MUST READ: Before executing any gcloud, REST API, or MCP command, you MUST read Usage Attribution. For commands executed directly in the terminal (never in generated scripts, Terraform, or user code), prefix gcloud with CLOUDSDK_METRICS_REQUEST_ATTRIBUTION="agent-skills/1.0 (skill:bigquery-bigframes)" and append agent-skills/1.0 (skill:bigquery-bigframes) to User-Agent headers.

Dataframe API best practices

  • Stay in the Cloud: Perform data cleaning, transformation, and analysis via BigFrames methods to leverage BigQuery's scale rather than downloading data.

  • Prefer partial ordering mode: Enable partial ordering mode right after importing BigFrames. This speeds up data processing significantly by relaxing row-sequence constraints.

    import bigframes.pandas as bpd
    bpd.options.bigquery.ordering_mode = 'partial'
    
  • Use peek() for data preview: Use peek(n) to preview data instead of head(n). peek(n) randomly samples n rows and is significantly faster. head(n) returns rows in strict order and fails in partial ordering mode unless the DataFrame has been explicitly sorted.

  • Avoid materializing data locally: Methods like to_pandas() download all data to client memory, bypassing BigQuery’s distributed computation and risking Out of Memory (OOM) errors. Do not materialize data locally unless:

    • The dataset is small enough to fit safely in memory.
    • An error message explicitly requires local materialization.
  • Prefer Dataframe API over SQL queries: Do not write raw SQL queries via read_gbq() if a DataFrame/Series method achieves the same result, as it breaks the Pandas abstraction and prevents lazy query execution.

  • Accessors over UDFs/Lambdas:

    • Use built-in accessors (e.g., df.col.str.*, df.col.dt.*) instead of remote User Defined Functions (UDFs). UDFs require extra resources and time to deploy.
    • Do not use lambdas with Series.map() or DataFrame.apply(). These methods do not accept functions without udf or remote_function decorators.
    # Avoid:
    df["upper"] = df["name"].map(lambda x: x.upper())
    
    # Prefer:
    df["upper"] = df["name"].str.upper()
    
  • Schema Verification: Do not assume the schema of intermediate outputs. Proactively verify schemas using .dtypes and inspect sample records using display() with .peek().

  • Visualization: Plot directly from the BigFrames DataFrame/Series when possible. BigFrames is compatible with Matplotlib and Seaborn. If direct plotting fails, use the .plot accessor. If the dataset is too large to plot, aggregate or sample the data before calling .to_pandas() to plot locally.

Machine Learning

  • Use bigframes.bigquery.ml package: Do not use Scikit-learn or other ML libraries with BigQuery DataFrames. Standard Scikit-learn models require bringing data into local client memory, whereas bigframes.bigquery.ml delegates training directly to BigQuery's scalable ML engine. Import functions from bigframes.bigquery.ml.

Reference Directory

BigFrames ML (Legacy)

The BigFrames ML package (bigframes.ml) is a legacy package that mimics the scikit-learn API but is no longer recommended for new projects. Only use this package if the user explicitly requests BigFrames ML.

  • Legacy Imports: When legacy BigFrames ML is requested, import tools and classes from bigframes.ml instead of bigframes.bigquery.ml.
  • DataFrame Return on Prediction: Unlike Scikit-learn, BigFrames' predict() method always returns a DataFrame containing both predictions and features, rather than a single series of predictions.
  • No random_state: Do not pass a random_state argument when instantiating BigFrames ML models, as this parameter is not supported in the BigFrames ML package.
  • Automatic Scaling: Do not use OneHotEncoder or StandardScaler unless explicitly requested, as scaling is handled automatical
常见问题

它会下载整张表吗?

不会。它把工作保留在 BigQuery 中,避免把每一行都拉到你的电脑上。

这是只用 SQL 的工作吗?

不是。如果以 SQL 为主,或需要基础的 Python 客户端库,请使用 bigquery-basics 技能。

预览方法是什么?

这个技能建议使用 peek 快速抽样行,而不是速度较慢的 head。

详情

作者的原始描述

Generates Python code using BigQuery DataFrames (BigFrames). Use by default for any Python data task involving BigQuery, including data processing, analysis, and machine learning. Don't use for SQL-first workflows or the google-cloud-bigquery client library — use bigquery-basics.

repo: google/skills

热度

GitHub 星标
22k
排名
#10226
许可证
Apache-2.0
更新时间
2026/11/2

这个技能有用吗?

0

登录 后即可投票。

评论

  • …

同一仓库的更多技能

相似技能