Chapter 4. Data Structures and Data Types
Now that you’ve been properly introduced, it’s time to focus on how Polars works.
Data comes in many shapes and sizes, all of which need to be stored in proper structures in order to work with them. To accommodate all the data you’ll be working with, Polars implements the Arrow memory specification, which provides a vast array of data types.
In this chapter you’ll learn about:
-
The structures Polars uses to store data
-
The different data types that are available
-
Some of the data types that aren’t so straightforward
Let’s start the beautiful journey of learning about Polars.
The instructions to get any files you might need are in Chapter 2. We assume that you have the files in the data subdirectory.
Series, DataFrames, and LazyFrames
Polars stores all of its data in a Series or a DataFrame.
A Series is a one-dimensional data structure that holds a sequence of values. All values in a Series have the same data type, like Integers, Floats, or Strings. Series can exist on their own, but they’re most commonly used as columns in a DataFrame.
An example of a Series is the following:
sales_series=pl.Series("sales",[150.00,300.00,250.00])sales_series
shape: (3,) Series: 'sales' [f64] [ 150.0 300.0 250.0 ]
A DataFrame is a two-dimensional data structure that organizes data in a table format, with rows and columns. Internally, it’s represented as a sequence of multiple Series, each with the same length. To dive deeper into the inner workings ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access