Skip to content

Instantly share code, notes, and snippets.

@crawles
Created February 14, 2020 15:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save crawles/8c04959c67563d75d94b377d122cba0a to your computer and use it in GitHub Desktop.
Save crawles/8c04959c67563d75d94b377d122cba0a to your computer and use it in GitHub Desktop.
Run a preview in bigquery using the `head` command. Save the result to a pandas df.
from io import StringIO
def head(table, n=10):
head_list = !bq head --n $n --table $table
head_str = '\n'.join([head_list[1]] + head_list[3:-1])
return pd.read_csv(StringIO(head_str), delimiter="|").iloc[:, 1:-1]
df = head('publicdata:samples.natality')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment