Created
January 4, 2024 17:33
-
-
Save davidauza-engineer/4beb411e115ff6302902f79e3c3d4fde to your computer and use it in GitHub Desktop.
Python Generic Script
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
import snowflake.connector | |
import pandas as pd | |
from Config_file import * | |
# Información de conexión genérica a una base de datos | |
user = USER | |
password = PASSWORD | |
account = ACCOUNT | |
warehouse = WAREHOUSE | |
database = DATABASE | |
schema = SCHEMA | |
role = ROLE | |
# Crea la conexión a la base de datos | |
conn = snowflake.connector.connect( | |
user=user, | |
password=password, | |
account=account, | |
warehouse=warehouse, | |
database=database, | |
schema=schema, | |
role=role | |
) | |
# Crear un cursor para ejecutar consultas | |
cur = conn.cursor() | |
# Ejecutar consultas genéricas | |
consulta1 = "SELECT * FROM DATABASE_ESQUEMA.TABLA1" | |
consulta2 = "SELECT * FROM DATABASE_ESQUEMA.TABLA2" | |
# Lista de consultas | |
consultas = [consulta1, consulta2] | |
# Procesar cada consulta y almacenar los resultados en DataFrames | |
dataframes = [] | |
for consulta in consultas: | |
cur.execute(consulta) | |
results = cur.fetchall() | |
df = pd.DataFrame(results, columns=[desc[0] for desc in cur.description]) | |
dataframes.append(df) | |
# Concatenar todos los DataFrames | |
df_concatenado = pd.concat(dataframes, ignore_index=True) | |
# Procesamiento adicional y generación de nuevas columnas si es necesario | |
# ... | |
# Cerrar la conexión a la base de datos | |
cur.close() | |
conn.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Esta pendiente Config_file.py para poder tener las credenciales necesarias para acceder a la base de datos y tener un resultado, seria de mucha ayuda que la pudieran subir
Andres Eduardo Varela