本文整理匯總了Python中pandas_gbq.read_gbq方法的典型用法代碼示例。如果您正苦於以下問題:Python pandas_gbq.read_gbq方法的具體用法?Python pandas_gbq.read_gbq怎麽用?Python pandas_gbq.read_gbq使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類pandas_gbq
的用法示例。
在下文中一共展示了pandas_gbq.read_gbq方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: get_definitions
# 需要導入模塊: import pandas_gbq [as 別名]
# 或者: from pandas_gbq import read_gbq [as 別名]
def get_definitions(self):
'''get the definitions from the master source
Returns:
df (pandas dataframe): dataframe
'''
projectid = self.config["definitions"]['project']
if 'query' in self.config["definitions"]:
q = self.config["definitions"]['query']
else:
dataset = self.config["definitions"]['dataset']
table = self.config["definitions"]['table']
q = """SELECT * FROM `%s.%s`""" % (dataset, table)
return pandas_gbq.read_gbq(q, project_id=projectid)
示例2: main
# 需要導入模塊: import pandas_gbq [as 別名]
# 或者: from pandas_gbq import read_gbq [as 別名]
def main(project_id):
# [START bigquery_pandas_gbq_read_gbq_simple]
import pandas_gbq
# TODO: Set project_id to your Google Cloud Platform project ID.
# project_id = "my-project"
sql = """
SELECT country_name, alpha_2_code
FROM `bigquery-public-data.utility_us.country_code_iso`
WHERE alpha_2_code LIKE 'A%'
"""
df = pandas_gbq.read_gbq(sql, project_id=project_id)
# [END bigquery_pandas_gbq_read_gbq_simple]
print(df)
return df
示例3: main
# 需要導入模塊: import pandas_gbq [as 別名]
# 或者: from pandas_gbq import read_gbq [as 別名]
def main(project_id):
# [START bigquery_pandas_gbq_read_gbq_legacy]
sql = """
SELECT country_name, alpha_2_code
FROM [bigquery-public-data:utility_us.country_code_iso]
WHERE alpha_2_code LIKE 'Z%'
"""
df = pandas_gbq.read_gbq(
sql,
project_id=project_id,
# Set the dialect to "legacy" to use legacy SQL syntax. As of
# pandas-gbq version 0.10.0, the default dialect is "standard".
dialect="legacy",
)
# [END bigquery_pandas_gbq_read_gbq_legacy]
print(df)
return df
示例4: test_read_gbq_should_use_dialect
# 需要導入模塊: import pandas_gbq [as 別名]
# 或者: from pandas_gbq import read_gbq [as 別名]
def test_read_gbq_should_use_dialect(mock_bigquery_client):
import pandas_gbq
assert pandas_gbq.context.dialect is None
pandas_gbq.context.dialect = "legacy"
pandas_gbq.read_gbq("SELECT 1")
_, kwargs = mock_bigquery_client.query.call_args
assert kwargs["job_config"].use_legacy_sql
pandas_gbq.context.dialect = "standard"
pandas_gbq.read_gbq("SELECT 1")
_, kwargs = mock_bigquery_client.query.call_args
assert not kwargs["job_config"].use_legacy_sql
pandas_gbq.context.dialect = None # Reset the global state.
示例5: get_pandas_df
# 需要導入模塊: import pandas_gbq [as 別名]
# 或者: from pandas_gbq import read_gbq [as 別名]
def get_pandas_df(
self, sql: str, parameters: Optional[Union[Iterable, Mapping]] = None, dialect: Optional[str] = None
) -> DataFrame:
"""
Returns a Pandas DataFrame for the results produced by a BigQuery
query. The DbApiHook method must be overridden because Pandas
doesn't support PEP 249 connections, except for SQLite. See:
https://github.com/pydata/pandas/blob/master/pandas/io/sql.py#L447
https://github.com/pydata/pandas/issues/6900
:param sql: The BigQuery SQL to execute.
:type sql: str
:param parameters: The parameters to render the SQL query with (not
used, leave to override superclass method)
:type parameters: mapping or iterable
:param dialect: Dialect of BigQuery SQL – legacy SQL or standard SQL
defaults to use `self.use_legacy_sql` if not specified
:type dialect: str in {'legacy', 'standard'}
"""
if dialect is None:
dialect = 'legacy' if self.use_legacy_sql else 'standard'
credentials, project_id = self._get_credentials_and_project_id()
return read_gbq(sql,
project_id=project_id,
dialect=dialect,
verbose=False,
credentials=credentials)
示例6: test_read_gbq_should_save_credentials
# 需要導入模塊: import pandas_gbq [as 別名]
# 或者: from pandas_gbq import read_gbq [as 別名]
def test_read_gbq_should_save_credentials(mock_get_credentials):
import pandas_gbq
assert pandas_gbq.context.credentials is None
assert pandas_gbq.context.project is None
pandas_gbq.read_gbq("SELECT 1", dialect="standard")
assert mock_get_credentials.call_count == 1
mock_get_credentials.reset_mock()
assert pandas_gbq.context.credentials is not None
assert pandas_gbq.context.project is not None
pandas_gbq.read_gbq("SELECT 1", dialect="standard")
mock_get_credentials.assert_not_called()
示例7: method_under_test
# 需要導入模塊: import pandas_gbq [as 別名]
# 或者: from pandas_gbq import read_gbq [as 別名]
def method_under_test(credentials):
import pandas_gbq
return functools.partial(pandas_gbq.read_gbq, credentials=credentials)