I have used Python for over ten years. Most of that time I built software and automation tools. In the last few months I started working with data science.
The tools in Python for data work are excellent. Libraries like Pandas, NumPy and Matplotlib let me load, clean and show data in just a few lines of code.
At the same time I have written Swift code for Apple platforms for many years. I created server applications and iOS projects. Swift feels clean, modern and safe. But when I worked with data I missed the fast interactive style that Pandas gives in notebooks.
So I asked myself: can I bring some of that data experience into Swift?
The answer led me to Apples TabularData framework. It offers a DataFrame that works like Pandas. I also used Swift Playgrounds to run code line by line and see results right away.
First Steps with Data in Swift
I wanted to try a simple task. I took a small weather dataset and analyzed it in two ways. First with Python and Pandas. Then with Swift and TabularData.
This was not a speed test or a full comparison. Pandas is much more complete. I only wanted to see how close Swift can come to a normal data workflow.
Here is the file I used, named weather.csv:
date,temp_max,temp_min,precipitation
2024-07-01,30,22,0
2024-07-02,31,21,0
2024-07-03,28,20,5
2024-07-04,29,19,2
How I Work with Pandas
After many years the Pandas code feels natural:
import pandas as pd
df = pd.read_csv("weather.csv")
df["temp_range"] = df["temp_max"] - df["temp_min"]
df.dropna(inplace=True)
print(df.head())
print("Average Max Temp:", df["temp_max"].mean())
print("Total Rainfall:", df["precipitation"].sum())
I load the file, add a new column, remove empty rows and calculate basic numbers. It is quick and easy.
This simple flow is why Pandas is so popular for data work.
This time I did not open Jupyter or Matplotlib. I opened Swift Playgrounds instead.
Moving the Same Steps to Swift
I started a macOS Playground and added two imports:
import TabularData
import Foundation
Loading the CSV file was straightforward:
let fileURL = URL(fileURLWithPath: "/Users/Shared/weather.csv")
let df = try DataFrame(contentsOfCSVFile: fileURL)
df.prefix(5)
The table appeared in the Playground sidebar. It was not as detailed as Pandas output but it gave me the same feeling of exploring data.
Next I added a column for the temperature range. The Swift way needs a few more lines:
var df = df.dropMissingRows()
let tempRange = zip(df["temp_max"], df["temp_min"]).map(-)
df.append(column: Column(name: "temp_range", contents: tempRange))
It takes more code than Pandas. But every step is clear. This makes mistakes less likely later.
Getting Results in Swift
Printing the numbers felt familiar and safe:
let avgTemp = df.mean(of: "temp_max")
let totalRain = df.sum(of: "precipitation")
print("Average Max Temp:", avgTemp ?? 0)
print("Total Rainfall:", totalRain ?? 0)
The values matched the Pandas results exactly.
Pandas is built for fast exploration. Swift is built for safety and clear types. You write a bit more but you gain confidence.
Swift Playgrounds make the process enjoyable. They are interactive and clean. You write normal Swift code and see results instantly.
Creating Charts in Swift
In Pandas I normally use Matplotlib to draw lines:
import matplotlib.pyplot as plt
plt.plot(df["date"], df["temp_max"], label="Max Temp")
plt.plot(df["date"], df["temp_min"], label="Min Temp")
plt.legend()
plt.show()
In Swift I used the Charts framework with SwiftUI:
import Charts
let chart = Chart(df.rows, id: \.self) {
LineMark(
x: .value("Date", $0["date"]!),
y: .value("Max Temp", $0["temp_max"]!)
)
LineMark(
x: .value("Date", $0["date"]!),
y: .value("Min Temp", $0["temp_min"]!)
)
}
chart
The chart appeared directly in the Playground.
For someone used to Python plotting this felt smooth and exciting. It is not as flexible yet but it shows that Swift can handle visualization too.
What I Learned from This Test
This small project taught me a few clear points. Pandas is still the best choice for big data tasks because it is fast, powerful and has a huge community. TabularData adds useful data tools to Swift but it does not replace Pandas. Instead it gives a safe way to work with tables inside Swift code. Swift Playgrounds are great for trying data ideas since they feel like notebooks but stay inside the normal Swift environment. SwiftUI Charts make simple graphs easy and look good right in the code output.
After ten years with Python I did not expect Swift to feel good for data work. TabularData changed my view.
The framework is still young and misses many Pandas features. But it brings Swifts strengths: clean code, strong types and tight connection to Apple platforms.
For me, this experiment was less about comparing tools and more about curiosity. It showed me that Swift can handle data in ways I didn’t expect — not as a replacement for Python, but as a new space to explore ideas, visualize results, and keep everything within Apple’s ecosystem.
Top comments (0)