150x Pandas Speed-Up: cuDF in Python

NeuralNine · Beginner ·📰 AI News & Updates ·1y ago
Skills: ML Pipelines80%

Key Takeaways

This video demonstrates how to use RAPIDS cuDF with NVIDIA GPUs in Python to achieve a 150x speed-up in Pandas dataframes. The video showcases the cuDF library as a replacement for Pandas to improve performance.

Full Transcript

what is going on guys welcome back in this video today we're going to learn how to massively speed up working with panda data frames by using a GPU data frame Library called CDF which is designed for fast and efficient data manipulation on gpus from Nvidia so let us get right into [Music] ited all right so we're going to learn how to massively speed up working with Panda's data frames in this video today by using a Library called KF which is designed for NVIDIA gpus and allows us to use our gpus to do data manipulation leading to a massive speed up when working with data frames now I do have some code here prepared to show you how this works and how much faster this is but first of all we need to make sure that we have the proper version of the CF package installed and for this we need to know what Cuda version is running on our system now of course this only works if you have a GPU that supports Cuda and if you have such a GPU on Linux you can run Nvidia DM I just Google how it works on Windows if it doesn't work in the same way uh and in my case here it says Cuda version 12.5 so I know I need the package for Cuda 12 so what I do is I type pip 3 install cf-c2 now if you have Cuda 11 you install cf- cu11 and so on so I already have this installed on my system and once you have this installed basically all you have to do is you have to replace pandas data frames by qf data frames nothing else changes and you have a massive massive speed up um in your operation so this first file that I have here what I do here is I Generate random values I have 10 to the^ of 8 rows which is quite a bit and what I do is I Generate random values I also have IDs and then I take this dictionary that is the result of doing that and I turn it into a pandis data frame and into a CDF data frame and then basically I just Group by ID and aggregate the value column so I just sum up all the values I do that here for pandas on the CPU and I do that with KF on the GPU and KF also uses the CPU if the GPU is not available or problematic or not reasonable or something like that um but I also have to append here sort index because since the GPU is doing everything in parallel the order is messed up a little bit but this is not really a problem so I just sort it and that's the only difference and for these two functions I measured the time and when I run this now you will see that for the pandas data frame uh it takes 1.1 seconds for the qdf data frame or for the coup data frame it takes uh 0.07 seconds which is a speed up of 15 or in percent of 1, 143% this is massive um this is an extreme speed up and I think I saw some where uh the claim that you can get a speed up of up to 150 so 150 times faster using kdf now I have a second script here main 2py uh where I load an actual data set uh which is the yellow trip data so it's a taxi data set uh in park format uh I load it here in pandas I load it here in KF and what I do here is some basic stuff like dropping all the Nan values um filtering for a trip distance larger than two and then also again grouping and then uh applying the mean operation or aggregation and the sum aggregation for these two columns and then I sort the values here by trip distance and then I get the result I do the exact same thing here for the Cuda data frame and if I run this code you are going to see after some time that the panda time was 0.46 seconds the CF time is 0.1 seconds so here we have a speed up of 4.5 so 4.5 times faster and in percent this is 355 per. so you can see that these operations are much faster using qdf even though nothing else changes so I just take the data frame and I turn it into a KF data frame or into a Cuda data frame you could say uh and it's much faster because it utilizes the GPU now one thing that you have to consider here is when you want to compare those values the resulting values for a equality or in terms of equality you have to do it with NP all close because these values are basically the same but not exactly because there are some slight differences here when it comes to floating Point numbers we're talking about very very small differences I actually print them here in the end um we're talking about something like e -10 so something very very small but we have some small imprecisions when it comes to floating Point numbers because the arithmetic the floating Point arithmetic is done differently on a CPU and on a GPU so we will have some small differences which means that if we compare for exact equality we're not going to get a true we're going to get a false but we have this function NP all close to basically uh see if the values are close enough and in this case there are I do the same thing here for the individual value strip distance and total amount so we can see we get the same results uh with some slight very very small uh differences but it's not necessarily because the operations are wrong but just because these small inconsistencies or the small imprecisions on a floating point or in the floating Point arithmetics are just different ones they're also there with a CPU but they're just different ones on a GPU so this is how you do that but there's an even simpler way to do that in Jupiter notebook so in Jupiter notebooks all you have to do is you have to load an extension and this extension uh will allow you to not even have to use KF at all so if I open up actually let me navigate here to the current directory um I can open up a Jupiter lap instance here and um I can copy paste some code so I can actually go and uh let's actually use this code here let's copy paste that go to the browser open a new jupyter notebook save it as main ipynb copy paste this and now let's say I don't even want to have these different um these different uh data frame types I can actually remove everything that has to do with CF I have my basic pandas code so I can remove also this here and I can remove also this here and I can remove this here and also the speed up calculations and all the comparisons so I just have the operation in pandas I can run this and we will get something like 1 point something yeah 1.09 seconds now the great thing that I can do here is I can add one line to my Jupiter notebook which is percent load extension and then just KF pandas and by doing that it automatically uses qdf and not pandas anymore so you can see that now the operation took 0.07 seconds even though I don't use CF at all I don't use any CF explicitly I just have my pandas code without even changing anything about it and just by saying I want to use CF p pandas it is using KF pandas and I have a speed up which is massive uh now the best way to to just uh you know disable this again is to restart the kernel so that's the best thing that you can do if you want to or actually I don't even know if that's going to solve it maybe I have to even start the Jupiter laap instance no actually restarting the kernel is fine uh but yeah if you say load extension in a Jupiter notebook KF panda you're automatically telling your environment or your Colonel to use KF instead of pandas and to use the GPU when possible which will leave to a which will lead to a massive speed up so that's it for today's video I hope you enjoyed it and hope you learned something if so let me know by hitting a like button and leaving a comment in the comment section down below and of course don't forget to subscribe to this Channel and hit the notification Bell to not miss a single future video for free other than that thank you much for watching see you in the next video and bye for

Original Description

In this video, we learn how to massively speed up Pandas dataframes by using RAPIDS cuDF for NVIDIA GPUs in Python. ◾◾◾◾◾◾◾◾◾◾◾◾◾◾◾◾◾ 📚 Programming Books & Merch 📚 🐍 The Python Bible Book: https://www.neuralnine.com/books/ 💻 The Algorithm Bible Book: https://www.neuralnine.com/books/ 👕 Programming Merch: https://www.neuralnine.com/shop 💼 Services 💼 💻 Freelancing & Tutoring: https://www.neuralnine.com/services 🌐 Social Media & Contact 🌐 📱 Website: https://www.neuralnine.com/ 📷 Instagram: https://www.instagram.com/neuralnine 🐦 Twitter: https://twitter.com/neuralnine 🤵 LinkedIn: https://www.linkedin.com/company/neuralnine/ 📁 GitHub: https://github.com/NeuralNine 🎙 Discord: https://discord.gg/JU4xr8U3dm
Watch on YouTube ↗ (saves to browser)
Sign in to unlock AI tutor explanation · ⚡30

Playlist

Uploads from NeuralNine · NeuralNine · 0 of 60

← Previous Next →
1 Visualizing Stock Data With Candlestick Charts in Python
Visualizing Stock Data With Candlestick Charts in Python
NeuralNine
2 Python Beginner Tutorial #1 - Installation and First Program
Python Beginner Tutorial #1 - Installation and First Program
NeuralNine
3 Python Beginner Tutorial #2 - Variables and Data Types
Python Beginner Tutorial #2 - Variables and Data Types
NeuralNine
4 Python Beginner Tutorial #3 - Operators and User Input
Python Beginner Tutorial #3 - Operators and User Input
NeuralNine
5 Python Beginner Tutorial #4 - If Statements and Conditions
Python Beginner Tutorial #4 - If Statements and Conditions
NeuralNine
6 Python Beginner Tutorial #5 - Loops
Python Beginner Tutorial #5 - Loops
NeuralNine
7 Python Beginner Tutorial #6 - Sequences and Collections
Python Beginner Tutorial #6 - Sequences and Collections
NeuralNine
8 Python Beginner Tutorial #7 - Functions
Python Beginner Tutorial #7 - Functions
NeuralNine
9 Python Beginner Tutorial #8 - Exception Handling
Python Beginner Tutorial #8 - Exception Handling
NeuralNine
10 Python Beginner Tutorial #9 - File Operations
Python Beginner Tutorial #9 - File Operations
NeuralNine
11 Python Beginner Tutorial #10 - String Functions
Python Beginner Tutorial #10 - String Functions
NeuralNine
12 Python Intermediate Tutorial #1 - Classes and Objects
Python Intermediate Tutorial #1 - Classes and Objects
NeuralNine
13 Python Intermediate Tutorial #2 - Inheritance
Python Intermediate Tutorial #2 - Inheritance
NeuralNine
14 Python Intermediate Tutorial #3 - Multithreading
Python Intermediate Tutorial #3 - Multithreading
NeuralNine
15 Python Intermediate Tutorial #4 - Synchronizing Threads
Python Intermediate Tutorial #4 - Synchronizing Threads
NeuralNine
16 Python Intermediate Tutorial #5 - Events and Daemon Threads
Python Intermediate Tutorial #5 - Events and Daemon Threads
NeuralNine
17 Python Intermediate Tutorial #6 - Queues
Python Intermediate Tutorial #6 - Queues
NeuralNine
18 Python Intermediate Tutorial #7 - Sockets and Network Programming
Python Intermediate Tutorial #7 - Sockets and Network Programming
NeuralNine
19 Python Intermediate Tutorial #8 - Database Programming
Python Intermediate Tutorial #8 - Database Programming
NeuralNine
20 Python Intermediate Tutorial #9 - Recursion
Python Intermediate Tutorial #9 - Recursion
NeuralNine
21 Python Intermediate Tutorial #10 - XML Processing
Python Intermediate Tutorial #10 - XML Processing
NeuralNine
22 Python Intermediate Tutorial #11 - Logging
Python Intermediate Tutorial #11 - Logging
NeuralNine
23 Python Data Science Tutorial #1 - Anaconda and PyCharm Setup
Python Data Science Tutorial #1 - Anaconda and PyCharm Setup
NeuralNine
24 Python Data Science Tutorial #2 - NumPy Arrays
Python Data Science Tutorial #2 - NumPy Arrays
NeuralNine
25 Python Data Science Tutorial #3 - Numpy Functions
Python Data Science Tutorial #3 - Numpy Functions
NeuralNine
26 Python Data Science Tutorial #4 - Plotting Functions With Matplotlib
Python Data Science Tutorial #4 - Plotting Functions With Matplotlib
NeuralNine
27 Python Data Science Tutorial #5 - Subplots and Multiple Windows
Python Data Science Tutorial #5 - Subplots and Multiple Windows
NeuralNine
28 Python Data Science Tutorial #6 - Matplotlib Styling
Python Data Science Tutorial #6 - Matplotlib Styling
NeuralNine
29 Python Data Science Tutorial #7 - Bar Charts with Matplotlib
Python Data Science Tutorial #7 - Bar Charts with Matplotlib
NeuralNine
30 Python Data Science Tutorial #8 - Pie Charts with Matplotlib
Python Data Science Tutorial #8 - Pie Charts with Matplotlib
NeuralNine
31 Python Data Science Tutorial #9 - Plotting Histograms with Matplotlib
Python Data Science Tutorial #9 - Plotting Histograms with Matplotlib
NeuralNine
32 Python Data Science Tutorial #10 - Scatter Plots with Matplotlib
Python Data Science Tutorial #10 - Scatter Plots with Matplotlib
NeuralNine
33 Python Data Science Tutorial #11 - 3D Plotting with Matplotlib
Python Data Science Tutorial #11 - 3D Plotting with Matplotlib
NeuralNine
34 Python Data Science Tutorial #12 - Pandas Series
Python Data Science Tutorial #12 - Pandas Series
NeuralNine
35 Python Data Science Tutorial #13 - Pandas Data Frames
Python Data Science Tutorial #13 - Pandas Data Frames
NeuralNine
36 Python Data Science Tutorial #14 - Pandas Statistics
Python Data Science Tutorial #14 - Pandas Statistics
NeuralNine
37 Python Data Science Tutorial #15 - Pandas Sorting and Functions
Python Data Science Tutorial #15 - Pandas Sorting and Functions
NeuralNine
38 Python Data Science Tutorial #16 - Pandas Merging Data Frames
Python Data Science Tutorial #16 - Pandas Merging Data Frames
NeuralNine
39 Python Data Science Tutorial #17 - Pandas Queries
Python Data Science Tutorial #17 - Pandas Queries
NeuralNine
40 Python Machine Learning Tutorial #1 - What is Machine Learning?
Python Machine Learning Tutorial #1 - What is Machine Learning?
NeuralNine
41 Python Machine Learning Tutorial #2 - Linear Regression
Python Machine Learning Tutorial #2 - Linear Regression
NeuralNine
42 Python Machine Learning Tutorial #3 - K-Nearest Neighbors Classification
Python Machine Learning Tutorial #3 - K-Nearest Neighbors Classification
NeuralNine
43 Python Machine Learning #4 - Support Vector Machines
Python Machine Learning #4 - Support Vector Machines
NeuralNine
44 Python Machine Learning Tutorial #5 - Decision Trees and Random Forest Classification
Python Machine Learning Tutorial #5 - Decision Trees and Random Forest Classification
NeuralNine
45 Python Machine Learning Tutorial #6 - K-Means Clustering
Python Machine Learning Tutorial #6 - K-Means Clustering
NeuralNine
46 Python Machine Learning Tutorial #7 - Neural Networks
Python Machine Learning Tutorial #7 - Neural Networks
NeuralNine
47 Python Machine Learning Tutorial #8 - Handwritten Digit Recognition with Tensorflow
Python Machine Learning Tutorial #8 - Handwritten Digit Recognition with Tensorflow
NeuralNine
48 Generating Poetic Texts with Recurrent Neural Networks in Python
Generating Poetic Texts with Recurrent Neural Networks in Python
NeuralNine
49 Stock Portfolio Visualization with Matplotlib in Python
Stock Portfolio Visualization with Matplotlib in Python
NeuralNine
50 Analyzing Coronavirus with Python (COVID-19)
Analyzing Coronavirus with Python (COVID-19)
NeuralNine
51 Making Text Images Readable Again with Python and OpenCV
Making Text Images Readable Again with Python and OpenCV
NeuralNine
52 Neural Networks Simply Explained (Theory)
Neural Networks Simply Explained (Theory)
NeuralNine
53 Motion Filtering with OpenCV in Python
Motion Filtering with OpenCV in Python
NeuralNine
54 Top 5 Programming Languages To Learn in 2020
Top 5 Programming Languages To Learn in 2020
NeuralNine
55 Simple TCP Chat Room in Python
Simple TCP Chat Room in Python
NeuralNine
56 Image Classification with Neural Networks in Python
Image Classification with Neural Networks in Python
NeuralNine
57 Edge Detection with OpenCV in Python
Edge Detection with OpenCV in Python
NeuralNine
58 S&P 500 Web Scraping with Python
S&P 500 Web Scraping with Python
NeuralNine
59 Simple Sentiment Text Analysis in Python
Simple Sentiment Text Analysis in Python
NeuralNine
60 Introduction - Algorithms & Data Structures #1
Introduction - Algorithms & Data Structures #1
NeuralNine

This video teaches how to use RAPIDS cuDF to speed up Pandas dataframes by leveraging NVIDIA GPUs in Python. By replacing Pandas with cuDF, users can achieve significant performance improvements. The video provides a practical guide on how to integrate cuDF with Python.

Key Takeaways
  1. Install RAPIDS cuDF
  2. Import cuDF library in Python
  3. Replace Pandas dataframes with cuDF dataframes
  4. Use cuDF functions for data processing
  5. Test and compare performance with Pandas
💡 cuDF can provide a significant speed-up for data processing tasks compared to Pandas, making it a valuable tool for data-intensive applications.

Related Reads

Up next
THE NEW FEDORA HYPRLAND SETUP OF 2026 (Must TRY)
Ksk Royal
Watch →