Querying structured data with Azure OpenAI

An implementation with Python

Valentina Alto
Microsoft Azure
Published in
6 min readFeb 13, 2023

--

Imagine you have a lot of structured data and you want to extract relevant information from them. You might also want to generate some simulations, asking for specific KPIs but also generating reports about the main relevances caught in data.

In fact, with so much structured data, you might also be in a condition where you are not sure what the relevant information is.

The classical approach in this case would be that of doing some descriptive analytics using a statistical approach. It could be with Python, R, or SQL queries.

But what if you “ask” your datasets questions in natural language? And what if you ask not only to compute numerical output but also generate analysis about trends, KPIs, and best next actions?

In this article, I’m going to share some experiments It turned out that Azure OpenAI models work pretty well on that.

Preparing data

Let’s start by creating a pandas data frame of an imaginary Sales table:

import pandas as pd
import numpy as np

# Create dataframe with 1000 rows
df = pd.DataFrame({
'Sales Order': np.arange(1, 1001),
'Order Date': np.random.choice(pd.date_range(start='2020-01-01', end='2022-01-01')…

--

--

Valentina Alto
Microsoft Azure

Data&AI Specialist at @Microsoft | MSc in Data Science | AI, Machine Learning and Running enthusiast