- Python Data Mining Quick Start Guide
- Nathan Greeneltch
- 270字
- 2021-06-24 15:19:50
Databases
A relational database is one of the most common ways that enterprises can store data. So, loading from and interacting with databases is essential for most fieldwork. The Python library that we will use is sqlite3 and is included in Anaconda's package. Let's begin by connecting to the database, which is stored in a .db file, and included with the book materials. After we connect to the database, we will create a cursor object that we will use to traverse the object during a query. Next, we will select the entire contents of the boston table with the * condition and limit the rows to five (only so that we can display the output without overloading our console). Finally, we will execute() the query and fetchall(). The data returned from the query is controlled by the search teams (select and limit, in this case). The next section will introduce more common terms used for queries:
import sqlite3
sqlite_file = './data/boston.db'
# connecting to the database file
conn = sqlite3.connect(sqlite_file)
# initialize a cursor obect
cur = conn.cursor()
# define a traversing search
cur.execute("select * from boston limit 5;")
# fetch and print
data = cur.fetchall()
print(data)
The output from the print() statement is 5 records, each with 15 entries, which correspond to the rows and columns of the data table, respectively:

- GNU-Linux Rapid Embedded Programming
- Hands-On Deep Learning with Apache Spark
- 自動控制工程設計入門
- 大數據技術基礎
- PowerShell 3.0 Advanced Administration Handbook
- Visual FoxPro 6.0數據庫與程序設計
- Google App Inventor
- 中國戰略性新興產業研究與發展·智能制造裝備
- 筆記本電腦維修90個精選實例
- 工業自動化技術實訓指導
- Photoshop CS4數碼攝影處理50例
- 步步驚“芯”
- 手把手教你學Photoshop CS3
- Visual Basic項目開發案例精粹
- Instant Slic3r