0% found this document useful (0 votes)
22 views8 pages

Installing Sqlite Via Browser To Work in CMD

The document outlines the process of installing SQLite and using it within Jupyter Notebook, including commands for establishing database connections and executing SQL queries. It discusses the principles of relational databases, the use of Python libraries for database management, and how to manipulate data using Pandas. Additionally, it highlights the advantages of using Pandas for data analysis and its integration with other Python libraries.

Uploaded by

Dhruvee Vadhvana
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views8 pages

Installing Sqlite Via Browser To Work in CMD

The document outlines the process of installing SQLite and using it within Jupyter Notebook, including commands for establishing database connections and executing SQL queries. It discusses the principles of relational databases, the use of Python libraries for database management, and how to manipulate data using Pandas. Additionally, it highlights the advantages of using Pandas for data analysis and its integration with other Python libraries.

Uploaded by

Dhruvee Vadhvana
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

Installing SQLite via browser to work in cmd

Creating Database in cmd

To create database file inside the table


TO RUN sqlite in jupyter

Importing required library

Creating dataframe

OUTPUT

Establishing the connection to SQLite database

Giving folder name as people


The %load_ext sql command is a magic command used in Jupyter Notebook to load and
activate an SQL (Structured Query Language) extension. Magic commands in Jupyter
Notebook are special commands that start with a % symbol and provide additional
functionalities beyond standard Python.
When you execute %load_ext sql, it loads the SQL extension, which allows you to use SQL
queries directly within your Jupyter Notebook
%sql: This is a magic command in Jupyter Notebook that activates the SQL extension,
allowing you to work with SQL queries and databases interactively.
sqlite:///jupyter.db: This part of the command is the connection string or URL to the SQLite
database you want to connect to. It follows the format
%sql sqlite:///jupyter.db, it connects to an SQLite database file named 'jupyter.db', assuming
that the database file is located in the same directory where the Jupyter Notebook is running.
After executing the %sql sqlite:///jupyter.db command, you establish a connection to the
SQLite database, and you can then execute SQL queries directly in notebook cells using the
%sql magic command prefix.
Acquiring and storing data in relational databases
Acquiring and storing data in Python using relational databases involves utilizing
the principles of relational databases and leveraging appropriate Python libraries
for data access and manipulation.
Relational Databases and SQL:
Relational databases use a tabular structure (tables) with rows (records) and
columns (attributes) to organize and store data. Each table represents a specific
entity, and relationships between entities are established using primary and
foreign keys.
Structured Query Language (SQL) is the standard language for interacting
with relational databases. It provides commands for creating, querying, updating,
and deleting data in the database.
Python Libraries for Relational Databases:
Python offers various libraries to interact with relational databases, such as
MySQL, PostgreSQL, SQLite, Oracle, and Microsoft SQL Server. Some popular
Python libraries for database management include:
• sqlite3: A built-in library for working with SQLite databases.
• mysql-connector-python: For connecting to and working with MySQL
databases.
• psycopg2: For connecting to and working with PostgreSQL databases.
• pyodbc: For connecting to and working with Microsoft SQL Server
databases.
Connecting to a Relational Database:
To interact with a relational database in Python, you first need to establish a
connection to the database server. The connection requires credentials like
username, password, host, and database name.
Creating Tables and Schema:
Before storing data, you need to create the necessary tables and define their
schema (structure). This involves specifying column names, data types, and any
constraints like primary keys or unique keys.
Acquiring Data and Inserting into the Database:
Data can be acquired from various sources, such as CSV files, APIs, or web
scraping. In Python, you can use libraries like pandas to load data from files or
requests for web data retrieval.
Once the data is acquired, you can use SQL INSERT queries to add the data to
the appropriate tables in the database.
Querying Data from the Database:
To retrieve data from the database, you can use SQL SELECT queries. Python
libraries allow you to execute SQL queries and fetch the results as Python objects
or DataFrames (if using pandas).
Updating and Deleting Data:
You can use SQL UPDATE and DELETE queries to modify or remove data from
the database based on specific conditions.
Handling Transactions:
In relational databases, a transaction is a sequence of one or more SQL operations
that must be executed together as a single unit. Python libraries provide
mechanisms to handle transactions, ensuring data integrity and consistency.
Closing the Database Connection:
Once you finish working with the database, it's essential to close the connection
properly to release resources.
A Brief Introduction-Relational Databases
In the context of Pandas, which is a powerful data manipulation library in Python,
we can relate the theory of relational databases to the data structures and
functionalities provided by Pandas.
Tables, Rows, and Columns:
In Pandas, the primary data structure for storing data is the Data Frame. You can
think of a data frame as a table with rows and columns, where each column
represents an attribute, and each row corresponds to a record or an observation.
Data Frames can be created from various data sources, such as CSV files, Excel
spreadsheets, SQL databases, or even by manually providing data.
Primary Key and Foreign Key:
While Pandas Data Frames do not explicitly enforce primary keys and foreign
keys like in a relational database, you can achieve a similar effect by setting an
index for a Data Frame. The index serves as a unique identifier for each row and
plays a role similar to the primary key.
To create relationships between Data Frames, you can use the merge () or join ()
functions in Pandas. These functions allow you to combine Data Frames based
on common columns, similar to using foreign keys to join tables in a relational
database.
Data Normalization:
Data normalization in Pandas involves splitting data into separate data frames to
reduce redundancy and improve data organization. For example, if you have a
data frame containing information about employees and their respective
departments, you might normalize the data into two separate Data Frames: one
for employees and one for departments.
Normalization in Pandas is typically done to ensure data integrity and avoid data
duplication, similar to the principles applied in relational databases.
Structured Query Language (SQL):
While Pandas is not an SQL database, it provides powerful querying capabilities
through the use of its query () and loc[] functions, among others. These functions
allow you to filter, select, and manipulate data in a data frame using SQL-like
syntax.
For example, you can use the query () function to filter rows based on specific
conditions, similar to using a WHERE clause in an SQL query.
Advantages of Pandas for Relational Data Analysis:
Pandas simplify the process of loading, manipulating, and analyzing data, making
it easy to work with relational-like data without the need for an external database.
It provides a wide range of data transformation and manipulation functions,
enabling users to perform tasks like grouping, aggregating, and merging data
efficiently.
Pandas also offers seamless integration with other data analysis libraries in
Python, such as NumPy, matplotlib, and Scikit-learn, allowing for comprehensive
data analysis and visualization.

You might also like