Snowflake for Beginners Part 5: Understanding Snowpark, Pandas and Mapping Data Between Systems

In my previous two blogs, we explored how I built a smoothie ordering application using Snowflake, Python and Streamlit, and how I introduced an external API to display nutritional information.

However, towards the end of the workshop, I encountered a problem that initially seemed quite small but introduced some important new concepts.

The fruit names stored in Snowflake did not always match the names expected by the external API.

To solve this problem, we needed to prepare our data differently and introduce another Python library called Pandas.

In this blog, I want to explore what Pandas is, how it differs from Snowpark and how we used it to help two different systems work together.


1. Understanding the problem

Imagine a customer selects Apples from our smoothie application.

Our Python code takes that selection and uses it to build an API request.

Plain text
https://my.smoothiefroot.com/api/fruit/Apples

However, the API expects Apple rather than Apples.

As humans, we immediately understand that these names refer to the same fruit. However, different software systems may expect information to be provided in a particular format.

We encountered similar differences with other fruits.

Name in SnowflakeName expected by the API
ApplesApple
BlueberriesBlueberry
Jack FruitJackfruit
StrawberriesStrawberry

One option would have been to change all the original fruit names in Snowflake.

However, we wanted to retain the names displayed to the customer while also having the correct values for our API requests.


2. Introducing the SEARCH_ON column

To solve this problem, we introduced another column in our FRUIT_OPTIONS table called SEARCH_ON.

This was done using SQL within Snowflake, rather than through Pandas.

It is worth revisiting some of the SQL concepts from my earlier blogs to understand how we can prepare this mapping.

Adding a new column

As our table already existed, we could use an ALTER TABLE statement to add another column.

SQL
ALTER TABLE SMOOTHIES.PUBLIC.FRUIT_OPTIONS
ADD COLUMN SEARCH_ON VARCHAR(100);

Our table would initially look something like this:

FRUIT_NAMESEARCH_ON
ApplesNULL
BlueberriesNULL
Jack FruitNULL
MangoNULL

The new column exists, but we haven't populated it with any values yet.

Populating the new column

Rather than manually entering every fruit name again, we can copy the existing fruit names into our new column.

SQL
UPDATE SMOOTHIES.PUBLIC.FRUIT_OPTIONS
SET SEARCH_ON = FRUIT_NAME
WHERE SEARCH_ON IS NULL;

Our table would now look like this:

FRUIT_NAMESEARCH_ON
ApplesApples
BlueberriesBlueberries
Jack FruitJack Fruit
MangoMango

Correcting the names that don't match

We can then update the individual values that need changing.

For example:

SQL
UPDATE SMOOTHIES.PUBLIC.FRUIT_OPTIONS
SET SEARCH_ON = 'Apple'
WHERE FRUIT_NAME = 'Apples';

We can repeat this process for the other fruits that require a different search value.

SQL
UPDATE SMOOTHIES.PUBLIC.FRUIT_OPTIONS
SET SEARCH_ON = 'Blueberry'
WHERE FRUIT_NAME = 'Blueberries';

The completed mapping contains information like this:

FRUIT_NAMESEARCH_ON
ApplesApple
BlueberriesBlueberry
Jack FruitJackfruit
StrawberriesStrawberry
MangoMango

The two columns now have different responsibilities.

FRUIT_NAME is what the customer sees.

SEARCH_ON is what our application uses when communicating with the API.

This is an example of data mapping. We are establishing a relationship between values used by different systems.

We have now prepared the mapping in Snowflake, but we still need to work out how Python can find the correct search value whenever a customer selects a fruit.


3. Retrieving both columns using Snowpark

In Blog 3, we explored how Snowpark allows Python to communicate with Snowflake.

Previously, we were mainly interested in retrieving the fruit names to populate our multiselect.

Now, we also need the SEARCH_ON column.

SQL
my_dataframe = session.table(
    "smoothies.public.fruit_options"
).select(
    col('FRUIT_NAME'),
    col('SEARCH_ON')
)

If we were writing this directly in SQL, it would be similar to:

SQL
SELECT FRUIT_NAME, SEARCH_ON
FROM SMOOTHIES.PUBLIC.FRUIT_OPTIONS;

Both examples describe the information we want to retrieve.

The difference is that in our Python application, we are using Snowpark.

The variable my_dataframe holds a Snowpark DataFrame representing the two selected columns.

At this point, we have described the data we want to work with.


4. What is Pandas?

Pandas is a Python library that allows us to work with, explore and manipulate data.

For example, Pandas can help us:

  • Select particular columns.
  • Find rows that match certain conditions.
  • Sort and filter information.
  • Perform calculations on data.

One of the main structures used in Pandas is called a DataFrame.

A DataFrame allows us to work with information organised into rows and columns, similar to a spreadsheet or a database table.

To use Pandas, we imported the library:

Python
import pandas as pd

Just as we used st as a shorter name for Streamlit, pd is a commonly used shorter name for Pandas.

However, this introduced a question for me.

If Snowpark already provides a DataFrame, why are we introducing another type of DataFrame?


5. Snowpark DataFrame vs Pandas DataFrame

Although both allow us to work with structured data, they do not work in exactly the same way.

A Snowpark DataFrame allows us to describe operations that can be performed within Snowflake.

A Pandas DataFrame allows us to work with retrieved data directly within our Python environment.

Snowpark DataFramePandas DataFrame
Works with data in SnowflakeWorks with data in Python
Processing generally takes place in SnowflakeProcessing takes place in the Python environment
Useful for processing large datasets within SnowflakeUseful for exploring and manipulating data that fits in memory

Think of a teacher working with a central school database.

The original student records are stored in the school's system. However, a teacher might retrieve a small set of those records into a spreadsheet to carry out some additional analysis.

The original records remain in the central system, but the teacher now has a separate copy to work with.

This is similar to what we are doing with Snowpark and Pandas.

Why did we use Pandas in our application?

We could have used Snowpark to perform the lookup directly within Snowflake.

However, our fruit table contained a relatively small amount of information.

By retrieving the data into a Pandas DataFrame, we could perform the individual fruit lookups directly within Python without needing to issue another Snowflake query for every selected fruit.

This does not mean that Pandas is better than Snowpark.

They are different tools, and understanding when to use each one is more important than simply knowing that both exist.


6. Converting our Snowpark DataFrame into a Pandas DataFrame

To make this conversion, we used the following line of code:

Plain text
pd_df = my_dataframe.to_pandas()

Let's break this down.

my_dataframe is our Snowpark DataFrame.

.to_pandas() executes the Snowpark query, retrieves the results from Snowflake and converts them into a Pandas DataFrame.

pd_df is the new variable containing the Pandas DataFrame.

We could display this information in Streamlit using:

Plain text
st.dataframe(pd_df)

The result would look something like this:

IndexFRUIT_NAMESEARCH_ON
0ApplesApple
1BlueberriesBlueberry
2Jack FruitJackfruit
3StrawberriesStrawberry
4MangoMango

We now have two variables with different responsibilities.

VariableWhat it represents
my_dataframeOur Snowpark DataFrame
pd_dfOur Pandas DataFrame containing the retrieved data

It is worth noting that .to_pandas() is a Snowpark method that performs this conversion for us.

Revisiting lazy evaluation

In Blog 3, we explored how Snowpark can prepare an operation without immediately executing it.

This is called lazy evaluation.

When we initially created my_dataframe, we described the table and columns we wanted to work with.

When we use .to_pandas(), Snowpark needs to execute the query because we are asking for the actual results to be brought into Python.

This is similar to how .collect() triggers the execution of a Snowpark operation, although the two methods return different types of results.


7. Finding the correct search value using Pandas

We now have our Pandas DataFrame containing both fruit names and search values.

Imagine the customer selects Apples.

Plain text
fruit_chosen = "Apples"

Our objective is simple.

Find the row where FRUIT_NAME is Apples and retrieve the corresponding value from SEARCH_ON.

The answer should be Apple.

In our completed application, we used the following code:

Plain text
search_on = pd_df.loc[
    pd_df['FRUIT_NAME'] == fruit_chosen,
    'SEARCH_ON'
].iloc[0]

When I first looked at this line, it seemed quite complicated.

However, rather than trying to understand the entire instruction at once, I found it much easier to break it down into three smaller steps.

Step 1 — Find the matching row

Plain text
pd_df['FRUIT_NAME'] == fruit_chosen

The first part identifies the column we want to check.

Plain text
pd_df['FRUIT_NAME']

We then compare the values in that column with the fruit selected by the customer.

Plain text
== fruit_chosen

Notice that we are using two equals signs.

In Python, a single equals sign assigns a value, while two equals signs compare values.

If the selected fruit is Apples, Pandas checks each row.

IndexFRUIT_NAMEDoes it match Apples?
0ApplesTrue
1BlueberriesFalse
2Jack FruitFalse
3StrawberriesFalse
4MangoFalse

The result of this comparison tells Pandas which rows match our condition.

We have identified the correct row, but we haven't yet retrieved the search value.

Step 2 — Select the corresponding column using .loc

Plain text
pd_df.loc[
    pd_df['FRUIT_NAME'] == fruit_chosen,
    'SEARCH_ON'
]

The .loc operation allows us to select information from a Pandas DataFrame.

In this example, we are providing two pieces of information:

  • Which rows we want, based on our matching condition.
  • Which column we want to retrieve.

We are essentially asking Pandas:

Find the row where the fruit name matches Apples, and return the value from the SEARCH_ON column.

The intermediate result would look something like this:

Plain text
0    Apple
Name: SEARCH_ON

Although we can now see the correct value, Pandas has returned something called a Series.

For now, we can think of a Series as a one-dimensional collection of values, similar to a single column of information.

What we actually want is the individual text value Apple, so we can use it in our API request.

Step 3 — Extract the individual value using .iloc[0]

Plain text
.iloc[0]

The .iloc operation allows us to retrieve information based on its numerical position.

Python starts counting positions from zero, so position 0 means the first item.

Because we expect one matching fruit in our lookup, we retrieve the first value from the matching results.

The result is now:

Plain text
Apple

This value is assigned to our variable.

Plain text
search_on = "Apple"

An important distinction is that .iloc[0] retrieves the first item from the filtered results, not necessarily the first row of the original DataFrame.

For example, if the customer selected Blueberries, .loc would find the matching value Blueberry. Using .iloc[0] would then retrieve Blueberry because it is the first item in those filtered results.

We can now summarise the entire process.

CodePurpose
pd_df['FRUIT_NAME'] == fruit_chosenIdentify the matching rows
.locSelect SEARCH_ON from the matching rows
.iloc[0]Extract the first matching value
search_on =Store the result in a variable

What originally looked like a complicated line of Python is actually answering quite a simple question.

What is the corresponding search value for the fruit selected by the customer?

8. Checking that our code works

Before using the mapped value in our API request, we displayed it in Streamlit.

Plain text
st.write(
    'The search value for ',
    fruit_chosen,
    ' is ',
    search_on,
    '.'
)

The result in the application was:

Plain text
The search value for Apples is Apple .

Although this message isn't necessary for the customer's final experience, it was useful during development.

It allowed us to check that our Python code was retrieving the correct value before passing it to the API.

This is something I am beginning to appreciate when learning Python.

Sometimes it is easier to display the contents of a variable and check what is happening rather than trying to understand everything from the code alone.

We used a similar approach in my earlier Snowflake blogs, where we checked our data before moving on to the next stage.

9. Using the mapped value in our API request

Now that we have retrieved the correct search value, we can return to the API code from Blog 4.

Previously, we were using the fruit selected by the customer directly.

Plain text
smoothiefroot_response = requests.get(
    "https://my.smoothiefroot.com/api/fruit/"
    + fruit_chosen
)

However, this could produce a URL that the API did not recognise.

In the completed application, we changed this to:

Plain text
smoothiefroot_response = requests.get(
    "https://my.smoothiefroot.com/api/fruit/"
    + search_on
)

We have only changed one variable, but this makes an important difference.

Using fruit_chosenUsing search_on
/fruit/Apples/fruit/Apple
/fruit/Blueberries/fruit/Blueberry
/fruit/Jack Fruit/fruit/Jackfruit

We can still use the original fruit name when displaying information to the customer.

Plain text
st.subheader(
    fruit_chosen + ' Nutrition Information'
)

But behind the scenes, we use the mapped value when communicating with the API.

The customer doesn't need to know that different systems are using different names.

Our application handles that process for them.

10. Bringing the concepts together inside our loop

In Blog 3, we spent time understanding how Python loops work.

In Blog 4, we applied that understanding to making an API request for each selected fruit.

We are now adding another step inside that same loop.

Here is the relevant section of our application, with some additional display instructions omitted for clarity.

Plain text
if ingredients_list:

    ingredients_string = ''

    for fruit_chosen in ingredients_list:

        ingredients_string += fruit_chosen + ' '

        search_on = pd_df.loc[
            pd_df['FRUIT_NAME'] == fruit_chosen,
            'SEARCH_ON'
        ].iloc[0]

        st.subheader(
            fruit_chosen + ' Nutrition Information'
        )

        smoothiefroot_response = requests.get(
            "https://my.smoothiefroot.com/api/fruit/"
            + search_on
        )

        sf_df = st.dataframe(
            data=smoothiefroot_response.json(),
            use_container_width=True
        )

Although this is a larger block of code, we already understand each of its individual parts.

Imagine a customer selects Apples, Blueberries and Mango.

IterationSelected fruitSEARCH_ON valueInformation requested
1ApplesAppleApple nutrition
2BlueberriesBlueberryBlueberry nutrition
3MangoMangoMango nutrition

During each iteration, Python:

  1. Adds the selected fruit to the smoothie order.
  2. Finds the correct API search value using Pandas.
  3. Creates a heading using the original fruit name.
  4. Requests the nutritional information.
  5. Displays the information in Streamlit.

Once the loop has finished, the application can prepare the SQL instruction for the completed order and save it when the customer clicks Submit Order.

Notice that we have continued to apply the same principles around indentation that we explored in the previous blogs.

The Pandas lookup and API request are inside the loop because we need to repeat these operations for every selected fruit.

The SQL INSERT is outside the fruit loop because we only want to save one complete smoothie order.

This is where the individual concepts from the previous blogs begin to come together.

11. What happens if there is no matching value?

Our lookup assumes that every selected fruit has a matching entry in our Pandas DataFrame.

But what would happen if no matching row existed?

Pandas would return an empty result, and .iloc[0] would produce an error because there is no first item to retrieve.

Similarly, if there were multiple matching rows with different search values, our code would simply take the first one.

This highlights the importance of maintaining accurate mapping data.

We want each fruit to have one clearly defined search value so that our application knows which value to use.

A more developed application would include additional checks to handle these situations.

For now, the important thing is to understand that the quality of our data directly affects whether the application works correctly.

12. Looking at the complete application

Across the last three blogs, we have gradually built up our understanding of the smoothie application.

Each technology plays a different role.

TechnologyResponsibility
SnowflakeStores available fruits, mapping values and customer orders
SQLPrepares, retrieves and updates data in Snowflake
SnowparkAllows Python to work with Snowflake
PandasHelps find the corresponding API search value
RequestsRetrieves external nutritional information
PythonControls the application logic
StreamlitProvides the interface for the customer
GitHubStores and manages the application code
Streamlit CloudHosts and runs the external application

What appears to the customer as a relatively simple application actually involves several different technologies working together.

Snowflake provides the available fruits.

The customer selects their ingredients through Streamlit.

Python uses Pandas to find the correct search value.

The Requests library communicates with the API.

Streamlit displays the nutritional information.

Finally, when the customer submits their order, Snowflake stores it.

Each technology has its own responsibility, but together they allow us to build a complete data application.

What have we learned?

ConceptPurpose
Data mappingEstablishes a relationship between values used by different systems
ALTER TABLEAdds a new column to an existing table
UPDATEPopulates or changes existing values
PandasAllows us to work with and manipulate data in Python
Snowpark DataFrameRepresents data and operations in Snowflake
Pandas DataFrameAllows us to work with retrieved data in Python
.to_pandas()Retrieves and converts Snowpark results into a Pandas DataFrame
==Compares values
.locSelects information using labels or matching conditions
.iloc[0]Retrieves the first item by its position
SEARCH_ONProvides the value expected by our external API

One of the most important distinctions from this blog is that Pandas did not create the relationship between Apples and Apple.

We prepared that relationship using SQL in Snowflake.

Pandas simply helped us find and use the information we had already prepared.

Final thoughts — Bringing my learning together

When I started this Snowflake learning journey, my focus was on understanding databases, loading files and querying information using SQL.

Across these five blogs, I have gradually moved from working with data inside Snowflake to building an application that allows users to interact with that data.

Looking back, each part of the series introduced something that became useful later on.

BlogMain area of learning
Part 1Snowflake fundamentals, loading and querying data
Part 2JSON, VARIANT and nested data
Part 3Building a data application using Python and Streamlit
Part 4Retrieving external information using APIs
Part 5Snowpark, Pandas and mapping data between systems

What I found particularly valuable was seeing how concepts from earlier parts of my learning became useful again later on.

Understanding JSON helped me when working with API responses.

Understanding Python loops and indentation helped me retrieve information for multiple fruits while ensuring that only one complete smoothie order was saved.

Understanding SQL helped me prepare the mapping data and store customer orders.

Understanding Pandas helped me bring information from different systems together.

When completing the workshop, there were occasions when I could follow the instructions and get the code working without fully understanding why certain lines were needed.

Writing these blogs and revisiting the code afterwards has given me an opportunity to address those gaps in my understanding.

Coming from a teaching background, I am reminded of the difference between being able to follow a worked example and being able to explain it or apply the same knowledge to a different problem.

There is still plenty for me to learn, particularly with Python, but I now have a much better understanding of how these different technologies fit together.

My next challenge is to apply this knowledge independently by building my own data application, taking what I have learned from the smoothie project and applying it to a different real-world problem.

The complete smoothie application code is available on my GitHub:

https://github.com/zainulNatha/smoothie-order-app

Author:
Zainul Abedin Natha
Powered by The Information Lab
1st Floor, 25 Watling Street, London, EC4M 9BR
Subscribe
to our Newsletter
Get the lastest news about The Data School and application tips
Subscribe now
© 2026 The Information Lab