Pandas and SQL Similarity 1

"<yoastmark

Pandas and SQL are the integral part of Data Science. It is used for data manipulation and analysis while SQL or Structured Query Language is usually used to fetch data, update the contents of the table, or operate on the structure of the database or tables, using any type of database tools, which will have a user interface to apply the operations on the database.

I believe Pandas and SQL are both similar in terms of analyzing the datasets, freshers like me find it difficult to remember the command syntax of both tool. A small effort from my end to show the command similarity.

Let’s Start..

Pandas Installation –

To work on both the tool, first we need to install them. I am using Anaconda distribution on my laptop which comes with all the required library pre-installed. To download Anaconda, please go to their site here

Launch the Jupyter Notebook

Jupyter notebook
Jupyter notebook

Load the pandas module,

pandas import

Note – If you are not using Anaconda, then pandas installation procedure can be found here

SQL Installation –

I am using Microsoft SQL Express edition for the demo purpose, which is available here for the download and installation procedure here.

Note – The only expectation here is that you should know pandas syntax.

Importing the data –

Pandas –

load data in to pandas
pandas data frame

I am using ‘read_excel’ because my source file is Excel and added sheet_name parameter because i want to import only first sheet from the excel file.

SQL –

You can import entire excel in to the SQL database with the help of SQL Import and Export wizard.

SQL Import Export
SQL Import Export

You have to choose source data source as ‘Microsoft Excel’ as shown in below screenshot

SQL Import Export select source
SQL Import Export select source

Choose the Excel file which you want to import and the correct Excel version

SQL Import Export select destination
SQL Import Export destination

Select ‘SQL Server Native Client 11.0’ in the ‘Choose a Destination’ screen

SQL Import Export select destination
SQL Import Export select destination SQL Server

Pick correct server name, authentication type and the database

You can select first option to copy entire data from the excel sheet or you can write custom SQL  query to import only required data. I will go ahead and select first option.

Here please select the sheet you to import under first column, new table will be created in the database with the sheet name (second column).

Select sheet to import in SQL database
Select sheet to import in SQL database

It will import data and will create new table in to the database which we provided.

SQL Table
SQL Table created after import

Lets work on the data now –

How to view entire data

Pandas –
pandas data frame
pandas data frame

‘df’ is nothing but a variable to store the data.  Pandas can store or read different type of data which is called as DataFrame.

You can type ‘print(df)’ or ‘df’ to view the entire data.

SQL –

Connect to the SQL Express using the SQL Management Studio

Click on the ‘New Query’

type below commands in the query field

‘select * from the dbo.Orders

SQL Select query

Hope you enjoyed the article on pandas and SQL, please visit for next set of commands.

2 thoughts on “Pandas and SQL Similarity 1”

Leave a Reply