How to make Pandas extremely fast without changing any code.

Underfitted · Intermediate ·📐 ML Fundamentals ·1y ago

Key Takeaways

Optimizes Pandas performance without changing code using advanced techniques

Full Transcript

let me show you how to make pandas many many times faster without changing your code this is probably going to be one of the best things that you learn today like if you are in the python World obviously you know pandas is probably the most popular library to manipulate to process data so I have here a quick example where I'm just going to load the data set is a large data set and we're going to run some queries and we are going to measure the performance of pandas on this data set so I'm going to start here by just importing pandas and as you can see here I'm printing out the name of the library that I'm currently using so that's pandas this is going to download the data set and the data set is the New York City parking data set from 2022 is parking violations it's a pretty big data set so there like I think it's like 1.5 million rows that we have in here so this section is just going to read this parquette file this is the name of the file and we're only interested in loading these five columns here in memory and then I'm going to print the first few rows from that data set and notice how I'm timing every single operation here like as we go forward I'm going to keep grabbing and recording how long it takes every one of these operations I'm going to run this it's going to take a couple seconds so here you get the first five rows uh printed out and I stored how long it took to do that operation in this variable here that we will later use okay so let's do now let's run a few queries this first query here will return which park in violation is the most commonly committed by vehicles from various US states so let me run this and we get all right so here are the five first elements here so you get the violation the description Etc uh the second query uh and by the way again I just timed that query and I stored it in query one then the second query will return which vehicle body types are the most frequently involved in parking violations so let's run that turns out that Suburbans are the first one followed by four doors SED Dan so who would have thought and the final query is how do parking violations vary across days of the weeks this is probably the most complex query the query that's going to take the longest here's the query here I'm printing the again the five the top five rows and then I'm timing that query uh so here we get Sundays and Saturdays and Mondays Etc so the final sale of this notebook here just takes all of these values the time it took to run every single operation and it sums them so we get how many seconds total uh it took pandas to do this and again this is just a very simple example you can think of like if you have an application that's using pandas in a more involved way with more data obviously you you can take an idea of how long that's going to take so the total time here was 12.54 seconds so I'm going to write down down that down here just so we remember that was 12.54 seconds and now comes the trick okay so I'm going to be using fire dots so fire dots is here in GitHub I'm going to leave a link to the repo somewhere here far dock is going to accelerate our code without having to change anything that's the important thing so I'm going to add here a new Cale put it at the top and let's install baru so that's going to be quiet uninstall if it already exists baru sorry I made a mistake here so I'm going to install the paru library and then I can replace this line so instead of importing pandas I'm going to import from fir do. pandas aspd and I'm just going to commend out this one here I'm going to run now so now every time I use PD I'm actually using the panda implementation of fire dots which they share the same interface so nothing in my code has to change so let's rerun everything here just going to go through all of it so you see what the performance uh optimization was by run this that took 2.81 seconds so 2.81 if I make that division that's 4.5 times faster without changing anything else literally a single line I was able to optimize my code 4.5 times make it 4. times five uh five faster this is a no-brainer if you have an application if you're using pandas check out firo again this is a there is a a GitHub repo here explains everything that you need to know they have more examples here they have compatibility charts Etc uh it's not only faster than pandas but it's even faster than polers which is an alternative to pandas and the good news with fire dos is that you don't have to change anything their website says that it could be up to 48 times faster than pandas I think this is an no-brainer I hope you enjoy it and I'll see you in the next one bye-bye

Original Description

I teach a live, interactive program that'll help you build production-ready Machine Learning systems from the ground up. Check it out here: https://www.ml.school To keep up with my content: • Twitter/X: https://www.twitter.com/svpino • LinkedIn: https://www.linkedin.com/in/svpino 🔔 Subscribe for more stories: https://www.youtube.com/@underfitted?sub_confirmation=1
Watch on YouTube ↗ (saves to browser)
Sign in to unlock AI tutor explanation · ⚡30

Playlist

Uploads from Underfitted · Underfitted · 0 of 60

← Previous Next →
1 Test-Time Augmentation In Machine Learning.
Test-Time Augmentation In Machine Learning.
Underfitted
2 Don't Replace Missing Values In Your Dataset.
Don't Replace Missing Values In Your Dataset.
Underfitted
3 Introduction to Adversarial Validation In Machine Learning.
Introduction to Adversarial Validation In Machine Learning.
Underfitted
4 Introduction To Autoencoders In Machine Learning.
Introduction To Autoencoders In Machine Learning.
Underfitted
5 Active Learning. The Secret of Training Models Without Labels.
Active Learning. The Secret of Training Models Without Labels.
Underfitted
6 Early Stopping. The Most Popular Regularization Technique In Machine Learning.
Early Stopping. The Most Popular Regularization Technique In Machine Learning.
Underfitted
7 The Confusion Matrix in Machine Learning
The Confusion Matrix in Machine Learning
Underfitted
8 3 Tips to Build a Career in Machine Learning (Unconventional Advice)
3 Tips to Build a Career in Machine Learning (Unconventional Advice)
Underfitted
9 I can predict cars CRASHING. And it's 99% accurate!
I can predict cars CRASHING. And it's 99% accurate!
Underfitted
10 A Critical Skill People Learn Too LATE: Learning Curves In Machine Learning.
A Critical Skill People Learn Too LATE: Learning Curves In Machine Learning.
Underfitted
11 The BEST Machine Learning Interview Strategy.
The BEST Machine Learning Interview Strategy.
Underfitted
12 OpenAI’s Whisper is AMAZING!
OpenAI’s Whisper is AMAZING!
Underfitted
13 5 Lessons You’re NOT Taught in School
5 Lessons You’re NOT Taught in School
Underfitted
14 TensorFlow On Apple Silicon. Step-by-Step Instructions
TensorFlow On Apple Silicon. Step-by-Step Instructions
Underfitted
15 Generating Images From Text. Stable Diffusion, Explained
Generating Images From Text. Stable Diffusion, Explained
Underfitted
16 The Wrong Batch Size Will Ruin Your Model
The Wrong Batch Size Will Ruin Your Model
Underfitted
17 8 Mistakes Holding Your Career Back | Machine Learning
8 Mistakes Holding Your Career Back | Machine Learning
Underfitted
18 AI Just Solved a 53-Year-Old Problem! | AlphaTensor, Explained
AI Just Solved a 53-Year-Old Problem! | AlphaTensor, Explained
Underfitted
19 Bias and Variance, Simplified
Bias and Variance, Simplified
Underfitted
20 Should You Stop Splitting Your Data Like This?
Should You Stop Splitting Your Data Like This?
Underfitted
21 The Function That Changed Everything
The Function That Changed Everything
Underfitted
22 This Model Caused A Nuclear Disaster
This Model Caused A Nuclear Disaster
Underfitted
23 Will Your Code Write Itself?
Will Your Code Write Itself?
Underfitted
24 The Simplest Encoding You’ve Never Heard Of
The Simplest Encoding You’ve Never Heard Of
Underfitted
25 Superhuman AI Cracked An Impossible Game! | DeepNash, Explained
Superhuman AI Cracked An Impossible Game! | DeepNash, Explained
Underfitted
26 Can you become a Data Scientist without a Ph.D?
Can you become a Data Scientist without a Ph.D?
Underfitted
27 How to 10x your productivity with ChatGPT?
How to 10x your productivity with ChatGPT?
Underfitted
28 Cheating the Prisoner's Dilemma
Cheating the Prisoner's Dilemma
Underfitted
29 We integrated OpenAI's Whisper with Spot
We integrated OpenAI's Whisper with Spot
Underfitted
30 The Machine Learning School program
The Machine Learning School program
Underfitted
31 We integrated ChatGPT with our robots
We integrated ChatGPT with our robots
Underfitted
32 Solving complex tasks using a Large Language Model (LLM)
Solving complex tasks using a Large Language Model (LLM)
Underfitted
33 5 problems when using a Large Language Model
5 problems when using a Large Language Model
Underfitted
34 We just discovered faster sorting algorithms!
We just discovered faster sorting algorithms!
Underfitted
35 The 3 most important updates to OpenAI's API.
The 3 most important updates to OpenAI's API.
Underfitted
36 People are divided! Does GPT-4 understand what it says?
People are divided! Does GPT-4 understand what it says?
Underfitted
37 How much should you charge hourly as a Machine Learning freelancer?
How much should you charge hourly as a Machine Learning freelancer?
Underfitted
38 Building a RAG application from scratch using Python, LangChain, and the OpenAI API
Building a RAG application from scratch using Python, LangChain, and the OpenAI API
Underfitted
39 Building a RAG application using open-source models (Asking questions from a PDF using Llama2)
Building a RAG application using open-source models (Asking questions from a PDF using Llama2)
Underfitted
40 How to evaluate an LLM-powered RAG application automatically.
How to evaluate an LLM-powered RAG application automatically.
Underfitted
41 Step by step no-code RAG application using Langflow.
Step by step no-code RAG application using Langflow.
Underfitted
42 I built a simple game using Langchain. Here is a step by step tutorial.
I built a simple game using Langchain. Here is a step by step tutorial.
Underfitted
43 I used the first AI Software Engineer for a week. This is happening.
I used the first AI Software Engineer for a week. This is happening.
Underfitted
44 I deployed a recommendation model. Testing Models In Production using Interleaving Experiments.
I deployed a recommendation model. Testing Models In Production using Interleaving Experiments.
Underfitted
45 How to run PyTorch, TensorFlow, and JAX on your Mac (Apple Silicon)
How to run PyTorch, TensorFlow, and JAX on your Mac (Apple Silicon)
Underfitted
46 How to train a model to generate image embeddings from scratch
How to train a model to generate image embeddings from scratch
Underfitted
47 Building an AI assistant that listens and sees the world (Step by step tutorial)
Building an AI assistant that listens and sees the world (Step by step tutorial)
Underfitted
48 Why are vector databases so FAST?
Why are vector databases so FAST?
Underfitted
49 A Machine Learning roadmap (the one I recommend to my students)
A Machine Learning roadmap (the one I recommend to my students)
Underfitted
50 How to build a real-time AI assistant (with voice and vision)
How to build a real-time AI assistant (with voice and vision)
Underfitted
51 An introduction to Mojo (for Python developers)
An introduction to Mojo (for Python developers)
Underfitted
52 How does Lexical Scoping in Mojo 🔥 works (under 3 minutes)
How does Lexical Scoping in Mojo 🔥 works (under 3 minutes)
Underfitted
53 Building a CI workflow for those who hate it (using GitHub Actions)
Building a CI workflow for those who hate it (using GitHub Actions)
Underfitted
54 How to run Python Code in Mojo 🔥
How to run Python Code in Mojo 🔥
Underfitted
55 AI will not take your job. Here is what I think will happen instead.
AI will not take your job. Here is what I think will happen instead.
Underfitted
56 How to fine-tune a model using LoRA (step by step)
How to fine-tune a model using LoRA (step by step)
Underfitted
57 Late initialization in Mojo🔥 (Python doesn't support this)
Late initialization in Mojo🔥 (Python doesn't support this)
Underfitted
58 The $1,000,000 problem AI can't solve
The $1,000,000 problem AI can't solve
Underfitted
59 A gentle introduction to RAG (using open-source models)
A gentle introduction to RAG (using open-source models)
Underfitted
60 Automating feedback using ChatGPT and Zapier
Automating feedback using ChatGPT and Zapier
Underfitted

Related Reads

Up next
How to Train AI to Play Games ? How AI Learns to Play ? Several Methods EXPLAINED
MaxonShire
Watch →