google-big-queryHow can I use Google BigQuery to install packages from PyPI?
Unfortunately, Google BigQuery does not support the installation of packages from PyPI. However, it is possible to use the BigQuery Python Client Library to access data stored in BigQuery from Python applications. The library can be installed using pip install google-cloud-bigquery
or pip install --upgrade google-cloud-bigquery
.
Once the library is installed, the following example code can be used to access BigQuery data from Python:
from google.cloud import bigquery
# Construct a BigQuery client object.
client = bigquery.Client()
# Make an API request.
query_job = client.query("SELECT * FROM `bigquery-public-data.usa_names.usa_1910_2013` LIMIT 10")
# Print results
for row in query_job:
print(row)
The output of the example code will be the first 10 rows of data from the bigquery-public-data.usa_names.usa_1910_2013
dataset:
Row(('Mary', 1910, 'F', 162436), {'state': 'AK', 'gender': 0, 'year': 1910, 'name': 'Mary', 'number': 162436})
Row(('Annie', 1910, 'F', 123672), {'state': 'AK', 'gender': 0, 'year': 1910, 'name': 'Annie', 'number': 123672})
Row(('Anna', 1910, 'F', 110480), {'state': 'AK', 'gender': 0, 'year': 1910, 'name': 'Anna', 'number': 110480})
Row(('Margaret', 1910, 'F', 89440), {'state': 'AK', 'gender': 0, 'year': 1910, 'name': 'Margaret', 'number': 89440})
Row(('Helen', 1910, 'F', 80345), {'state': 'AK', 'gender': 0, 'year': 1910, 'name': 'Helen', 'number': 80345})
Row(('Elizabeth', 1910, 'F', 73533), {'state': 'AK', 'gender': 0, 'year': 1910, 'name': 'Elizabeth', 'number': 73533})
Row(('Ruth', 1910, 'F', 65516), {'state': 'AK', 'gender': 0, 'year': 1910, 'name': 'Ruth', 'number': 65516})
Row(('Alice', 1910, 'F', 64511), {'state': 'AK', 'gender': 0, 'year': 1910, 'name': 'Alice', 'number': 64511})
Row(('Florence', 1910, 'F', 50935), {'state': 'AK', 'gender': 0, 'year': 1910, 'name': 'Florence', 'number': 50935})
Row(('Marie', 1910, 'F', 48639), {'state': 'AK', 'gender': 0, 'year': 1910, 'name': 'Marie', 'number': 48639})
The code above consists of the following parts:
from google.cloud import bigquery
: imports the BigQuery Python Client Library.client = bigquery.Client()
: creates a BigQuery client object.query_job = client.query("SELECT * FROM
bigquery-public-data.usa_names.usa_1910_2013LIMIT 10")
: runs a query to retrieve data from BigQuery.for row in query_job
: iterates through the query results and prints them.
Helpful links
More of Google Big Query
- How do I query Google BigQuery using XML?
- How can I use Google Big Query to split data?
- How can I use Google Big Query to analyze Reddit data?
- How do I set up a Google Big Query zone?
- How can I use Google Big Query to count the number of zeros in a given dataset?
- How can I use Google BigQuery to create a pivot table?
- How do I use the "not in" operator in Google BigQuery?
- How can I use Google Big Query to integrate with Zephyr?
- How can I use Google BigQuery to retrieve data from a specific year?
- How can I use Google Big Query to track revenue?
See more codes...