Introduzione ai database NoSQL
Jake Roach
Data Engineer
Definizione: Uno strumento di archiviazione NoSQL che salva dati in un formato flessibile e semi-strutturato, composto da coppie chiave-valore, chiave-array e chiave-oggetto (simile a 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';
Con il seguente risultato:

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)
Per creare una connessione a un database Postgres:
sqlalchemy.create_enginedb_engine sarà già pronta prima dell'esercizioimport 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)
Per scrivere ed eseguire una query:
query e db_engine alla funzione pd.read_sql()
Introduzione ai database NoSQL