Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases now! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Polars Cookbook

You're reading from   Polars Cookbook Over 60 practical recipes to transform, manipulate, and analyze your data using Python Polars 1.x

Arrow left icon
Product type Paperback
Published in Aug 2024
Publisher Packt
ISBN-13 9781805121152
Length 394 pages
Edition 1st Edition
Languages
Arrow right icon
Author (1):
Arrow left icon
Yuki Kakegawa Yuki Kakegawa
Author Profile Icon Yuki Kakegawa
Yuki Kakegawa
Arrow right icon
View More author details
Toc

Table of Contents (15) Chapters Close

Preface 1. Chapter 1: Getting Started with Python Polars FREE CHAPTER 2. Chapter 2: Reading and Writing Files 3. Chapter 3: An Introduction to Data Analysis in Python Polars 4. Chapter 4: Data Transformation Techniques 5. Chapter 5: Handling Missing Data 6. Chapter 6: Performing String Manipulations 7. Chapter 7: Working with Nested Data Structures 8. Chapter 8: Reshaping and Tidying Data 9. Chapter 9: Time Series Analysis 10. Chapter 10: Interoperability with Other Python Libraries 11. Chapter 11: Working with Common Cloud Data Sources 12. Chapter 12: Testing and Debugging in Polars 13. Index 14. Other Books You May Enjoy

To get the most out of this book

You will need a version of Python installed on your computer. All code examples have been tested using Python 3.11 on macOS. However, they should work with future version releases, too. Please note that Polars requires Python version 3.8 or higher.

Software/hardware covered in the book

OS requirements

Python >= 3.8

Windows, macOS, or Linux

In any Python project, it is recommended that you use a virtual environment to isolate the dependencies of your different projects. This allows you to install libraries into an environment without affecting the global Python installation or any other environments.

The use of a virtual environment is not required, however, you can easily create one with venv, which comes as part of the Python standard library. The following code creates a virtual environment:

$ python -m venv .venv

If you’re on macOS or Linux, the following code activates the virtual environment:

$ source .venv/bin/activate

You can use the following code for Windows:

$ .\.venv\Scripts\activate

There are several methods to install Polars and other Python libraries, however, in this book, we’ll be using pip, a popular package manager for Python.

You can either install the necessary libraries all at once or separately as you go. If you want to take the former approach, run the following code to install all the dependencies included in the requirements.txt file:

$ pip install -r requirements.txt

If you want to take the latter approach, you’ll first need to install Jupyter Notebook since all the code examples are written in Jupyter notebooks, and the book assumes you will be running the code using Jupyter Notebook.

Install JupyterLab with pip:

$ pip install notebook

Launch the notebook as follows:

$ jupyter notebook

Alternatively, you can install JupyterLab with pip with the following command:

$ pip install jupyterlab

Once installed, you can launch JupyterLab with the following command:

$ jupyter lab

You can also refer to the instructions on the Jupyter website: https://jupyter.org/install.

Note that if you’re using an Integrated Development Environment (IDE) such as Visual Studio Code (VSCode), you may not need to launch the notebook. Instead, you can open it directly in VSCode once you have installed the notebook/JupyterLab via pip and necessary VSCode extensions as required.

Several other libraries will be used throughout the book, including the Polars library. In each chapter and recipe, you’ll be instructed to install these when necessary; however, it may be good to install the required libraries beforehand.

Use the following command to install Polars:

$ pip install polars

You can specify optional dependencies in brackets, as in the following command:

$ pip install polars[pyarrow, pandas]

To install all the optional dependencies of Polars, specify the term all in the brackets:

$ pip install polars[all]

Also, while this most likely won’t be an issue, it is worth noting that your Polars should be version >= 1.0.0. That’s the version all the code in this book was tested on.

Now that you have set up your Python environment and have installed the dependencies, you’re ready to dive into the book contents.

If you are using the digital version of this book, we advise you to type the code yourself or access the code via the GitHub repository (link available in the next section). Doing so will help you avoid any potential errors related to the copying and pasting of code.

As Polars is growing rapidly day by day, it’s possible that some of the code snippets or methods and functions used in the book will be outdated by the time you’re reading it. We’ll do our best to note the new features and deprecations in the chapter notebooks, however, please feel free to contact us by sending an email or creating an issue in the GitHub repo.

Download the example code files

You can download the example code files for this book from GitHub at https://github.com/PacktPublishing/Polars-Cookbook/. If there’s an update to the code, it will be updated on the existing GitHub repository.

We also have other code bundles from our rich catalog of books and videos available at https://github.com/PacktPublishing/. Check them out!

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at €18.99/month. Cancel anytime