Informula

Informula

Share this post

Informula
Informula
How to Convert SQL into Python Pandas? Part 7 - Pivot & Unpivot

How to Convert SQL into Python Pandas? Part 7 - Pivot & Unpivot

Informula's avatar
Informula
Oct 18, 2023
∙ Paid

Share this post

Informula
Informula
How to Convert SQL into Python Pandas? Part 7 - Pivot & Unpivot
Share

Previously on How to Convert SQL into Python Pandas? Part 6, we talked about how to convert SQL statements into Pandas syntax. In this article, we will continue to discover more scenarios and operations.

Let’s create a simple table (data frame) to explain pivot/ unpivot ideas.

-- SQL
CREATE VIEW  main.invoices_country AS 
SELECT * 
FROM main.invoices
WHERE BillingCountry IN ('Germany', 'USA')
# Python Pandas

from google.colab import drive
drive.mount('/content/drive')

import sqlite3
import pandas as pd
import numpy as np

con = sqlite3.connect('/content/drive/MyDrive/Data/db/sample.db')
df_invoices_country = pd.read_sql("select * from invoices where BillingCountry in ('Germany', 'USA')", con)

Keep reading with a 7-day free trial

Subscribe to Informula to keep reading this post and get 7 days of free access to the full post archives.

Already a paid subscriber? Sign in
© 2025 Informula
Privacy ∙ Terms ∙ Collection notice
Start writingGet the app
Substack is the home for great culture

Share