Created
December 30, 2018 14:48
-
-
Save seonews-ru/bd1bbf357f972198d4eb13d039d02015 to your computer and use it in GitHub Desktop.
Как использовать Google BigQuery с помощью Python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Создаем тестовый dataframe | |
df = pd.DataFrame( | |
{ | |
'my_string': ['a', 'b', 'c'], | |
'my_int64': [1, 2, 3], | |
'my_float64': [4.0, 5.0, 6.0], | |
} | |
) | |
dataset_ref = client.dataset('my_dataset_2') # Определяем датасет | |
dataset = bigquery.Dataset(dataset_ref) | |
dataset = client.create_dataset(dataset) # Создаем датасет | |
table_ref = dataset_ref.table('new_table') # Определяем таблицу (при этом не создавая её) | |
result = client.load_table_from_dataframe(df, table_ref).result() # Тут данные из датафрейма передаются в таблицу BQ, при этом таблица создается автоматически из определенной в предыдущей строке |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment