NoSQL เบื้องต้น
Jake Roach
Data Engineer
นิยาม: เครื่องมือเก็บข้อมูล NoSQL ที่จัดเก็บข้อมูลในรูปแบบยืดหยุ่น กึ่งโครงสร้าง ประกอบด้วยคู่ key-value, key-array และ key-object (คล้ายกับ 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';
ผลลัพธ์ที่ได้:

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)
การสร้างการเชื่อมต่อกับฐานข้อมูล Postgres:
sqlalchemy.create_enginedb_engine จะถูกสร้างไว้ก่อนเริ่มแบบฝึกหัดimport 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)
ขั้นตอนการเขียนและรันคิวรี:
query และ db_engine ไปยังฟังก์ชัน pd.read_sql()
NoSQL เบื้องต้น