• Latest
  • Trending
Supercharge Your Pandas Code with Apache Spark

Supercharge Your Pandas Code with Apache Spark

March 2, 2022
Absa and Visa Extend Strategic Partnership to Advance Growth and Innovation Across Africa

Absa and Visa Extend Strategic Partnership to Advance Growth and Innovation Across Africa

July 29, 2025
French Telco Orange Hit by Cyber-Attack

French Telco Orange Hit by Cyber-Attack

July 29, 2025
ATC Ghana supports Girls-In-ICT Program

ATC Ghana supports Girls-In-ICT Program

April 25, 2023
Vice President Dr. Bawumia inaugurates  ICT Hub

Vice President Dr. Bawumia inaugurates ICT Hub

April 2, 2023
Co-Creation Hub’s edtech accelerator puts $15M towards African startups

Co-Creation Hub’s edtech accelerator puts $15M towards African startups

February 20, 2023
Data Leak Hits Thousands of NHS Workers

Data Leak Hits Thousands of NHS Workers

February 20, 2023
EU Cybersecurity Agency Warns Against Chinese APTs

EU Cybersecurity Agency Warns Against Chinese APTs

February 20, 2023
How Your Storage System Will Still Be Viable in 5 Years’ Time?

How Your Storage System Will Still Be Viable in 5 Years’ Time?

February 20, 2023
The Broken Promises From Cybersecurity Vendors

Cloud Infrastructure Used By WIP26 For Espionage Attacks on Telcos

February 20, 2023
Instagram and Facebook to get paid-for verification

Instagram and Facebook to get paid-for verification

February 20, 2023
YouTube CEO Susan Wojcicki steps down after nine years

YouTube CEO Susan Wojcicki steps down after nine years

February 20, 2023
Inaugural AfCFTA Conference on Women and Youth in Trade

Inaugural AfCFTA Conference on Women and Youth in Trade

September 6, 2022
  • Consumer Watch
  • Kids Page
  • Directory
  • Events
  • Reviews
Friday, 17 July, 2026
  • Login
itechnewsonline.com
  • Home
  • Tech
  • Africa Tech
  • InfoSEC
  • Data Science
  • Data Storage
  • Business
  • Opinion
Subscription
Advertise
No Result
View All Result
itechnewsonline.com
No Result
View All Result

Supercharge Your Pandas Code with Apache Spark

by ITECHNEWS
March 2, 2022
in Data Science, Leading Stories
0 0
0
Supercharge Your Pandas Code with Apache Spark

Pandas is a fast and powerful open-source data analysis and manipulation framework written in Python. Apache Spark is an open-source unified analytics engine for distributed large-scale data processing. Both are widely adopted in the data engineering and data science communities.

Even though there’s a great value in combining them in terms of productivity, scalability, and performance, it’s often overlooked. In this blog post, we’ll give a sneak peek into combining these tools to enjoy the best of both worlds!

YOU MAY ALSO LIKE

French Telco Orange Hit by Cyber-Attack

ATC Ghana supports Girls-In-ICT Program

For the purpose of this example, we’ve used a 1.9GB CSV file with fire department calls’ data, obtained from https://data.sfgov.org/Public-Safety/Fire-Department-Calls-for-Service/nuek-vuh3 as of 11/11/2019.

First, let’s try to calculate the total number of calls per zip code, using Pandas:

import pandas as pd
import time
# Record the start time
start = time.time()
# Read the CSV file with the header
pandasDF = pd.read_csv('/dbfs/databricks-datasets/timeseries/Fires/Fire_Department_Calls_for_Service.csv', header=0)
# Compute the total number of calls per zip code 
pandasDF.groupby('Zipcode of Incident')['Call Number'].count()
# Record the end time
end = time.time()
print('Command took ', end - start, ' seconds')

As you can see from the screenshot above, this took roughly 40 seconds on an i3.xlarge machine (with 30.5GB RAM and 4 cores). Keep in mind this is a small dataset for example purposes.

Can we improve it? With Pandas API on Spark – we can!

Apache Spark is a distributed processing engine, which will allow us to easily parallelize the computation.

Pandas API on Spark is a Pandas’ API compatible drop-in replacement which provides Pandas’ users the benefits of Spark, with minimal code changes.

It is also useful for PySpark users by supporting tasks that are easier to accomplish using Pandas, like plotting an Apache Spark DataFrame.

Let’s try the same example, but this time – using Pandas API on Spark:

import pyspark.pandas as ps
import time
# Record the start time
start = time.time()
# Read the CSV file with the header
pysparkDF = ps.read_csv('dbfs:/databricks-datasets/timeseries/Fires/Fire_Department_Calls_for_Service.csv', header=0)
# Compute the total number of calls per zip code 
pysparkDF.groupby('Zipcode of Incident')['Call Number'].count()
# Record the end time
end = time.time()
print('Command took ', end - start, ' seconds')

Notice we only had to change the import pandas as pd to import pyspark.pandas as ps.

using Apache Spark

This time, it took only about 7 seconds, which can be attributed to the fact it is executed in a distributed manner(as opposed to Pandas). In this example, we used the same i3.xlarge machine (with 30.5GB RAM and 4 cores) as the cluster driver, and 4 i3.xlarge machines for the cluster workers.

Essentially, Spark divided the 1.9GB file into smaller chunks (which are called “partitions”), and all partitions were processed concurrently across all machines in the cluster.

That means Spark was able to run 16 tasks concurrently, as you can see below:

using Apache Spark

It’s important to note that the larger the dataset – the greater performance improvement you can expect (e.g think about what would have happened if we chose a 1900GB dataset rather than a 1.9GB dataset…).

Using the Pandas API on Spark is just one of the options available to Python developers to easily use Spark and enjoy the performance, scalability, and stability benefits it provides.

Tags: Pandas Code with Apache Spark
ShareTweet

Get real time update about this post categories directly on your device, subscribe now.

Unsubscribe

Search

No Result
View All Result

Recent News

Absa and Visa Extend Strategic Partnership to Advance Growth and Innovation Across Africa

Absa and Visa Extend Strategic Partnership to Advance Growth and Innovation Across Africa

July 29, 2025
French Telco Orange Hit by Cyber-Attack

French Telco Orange Hit by Cyber-Attack

July 29, 2025
ATC Ghana supports Girls-In-ICT Program

ATC Ghana supports Girls-In-ICT Program

April 25, 2023

About What We Do

itechnewsonline.com

We bring you the best Premium Tech News.

Recent News With Image

Absa and Visa Extend Strategic Partnership to Advance Growth and Innovation Across Africa

Absa and Visa Extend Strategic Partnership to Advance Growth and Innovation Across Africa

July 29, 2025
French Telco Orange Hit by Cyber-Attack

French Telco Orange Hit by Cyber-Attack

July 29, 2025

Recent News

  • Absa and Visa Extend Strategic Partnership to Advance Growth and Innovation Across Africa July 29, 2025
  • French Telco Orange Hit by Cyber-Attack July 29, 2025
  • ATC Ghana supports Girls-In-ICT Program April 25, 2023
  • Vice President Dr. Bawumia inaugurates ICT Hub April 2, 2023
  • Home
  • InfoSec
  • Opinion
  • Africa Tech
  • Data Storage

© Copyright 2026, All Rights Reserved | iTechNewsOnline.Com - Powered by BackUPDataSystems

Welcome Back!

Login to your account below

Forgotten Password?

Retrieve your password

Please enter your username or email address to reset your password.

Log In

Add New Playlist

No Result
View All Result
  • Home
  • Tech
  • Africa Tech
  • InfoSEC
  • Data Science
  • Data Storage
  • Business
  • Opinion

© Copyright 2026, All Rights Reserved | iTechNewsOnline.Com - Powered by BackUPDataSystems

Are you sure want to unlock this post?
Unlock left : 0
Are you sure want to cancel subscription?
Go to mobile version