Introduction à NoSQL
Jake Roach
Data Engineer
Définition : Un outil de stockage NoSQL qui conserve les données dans un format souple et semi-structuré, composé de paires clé-valeur, clé-tableau et clé-objet (semblable à JSON).
$$
$$

{
"title": "Python for Data Analysis",
"price": 53.99,
"topics": [
"Data Science",
"Data Analytics",
...
],
"author": {
"first": "William"
...
}
}

SELECT
books -> 'title' AS title,
books -> 'price' AS price
FROM data_science_resources
WHERE
books -> 'author' ->> 'last' = 'Viafore';
Ce qui produit le résultat suivant :

import sqlalchemy
# Create a connection string, and an engine
connection_string = "postgresql+psycopg2://<user>:<password>@<host>:<port>/<database>"
db_engine = sqlalchemy.create_engine(connection_string)
Pour créer une connexion à une base Postgres :
sqlalchemy.create_enginedb_engine sera créée avant l'exerciceimport pandas as pd
# Build the query
query = """
SELECT
books -> 'title' AS title,
books -> 'price' AS price
FROM data_science_resources;
"""
# Execute the query
result = pd.read_sql(query, db_engine)
print(result)
Pour écrire et exécuter une requête :
query et db_engine à la fonction pd.read_sql()
Introduction à NoSQL