How to use SQL in Jupyter Notebook

I was using Linux for the past 2 years maybe and using MySQL workbench was so hard for me because of Linux. whenever I use to connect my server it always showed an error because of that I started searching for an alternative method and reliable source so I can use SQL for my data analyst work.

so here is the method……

import pandas as pd
import sqlite3 as sq

We need import two important library pandas and sqlite3. Pandas is one of most important and powerful library use data analysis. sqlite3 write sql queries and create connection with database.

pip install ipython-sql

let’s create database.

cnn= sq.connect('nick.db')

cnn use for to creating connection with Jupyter Notebook

df.to_sql('nilesh_kodag',cnn)

give name to table and connect with cnn (ya that’s my name)

%load_ext sql

load connection

%sql sqlite:///nick.db

People who understand SQL can employ the sqlite3 command-line shell (or various third-party SQLite access programs) to analyze large datasets. Raw data can be imported from CSV files, then that data can be sliced and diced to generate a myriad of summary reports. More complex analysis can be done using simple scripts written in Tcl or Python (both of which come with SQLite built-in)

%%sql
SELECT * FROM nilesh_kodag

index Name Age class
0 ravi 5 1
1 dulkar 75 5
2 salman 3 4

%%sql
SELECT count(*) FROM nilesh_kodag

you can find full code in my github

connect with me on linkedin, twitter

Self Learn Programmer | Digital Marketing | Data Science | Masters In Management Studies