Chapter 15. Reshaping
In the last chapter we focussed on aggregating data to create informative summaries. However, what should you do if the data is not in the right shape to perform these aggregations? Reshaping data is a crucial step in the data analysis process.
In this chapter, you’ll learn:
-
how to reshape data to make it more suitable for analysis.
-
how to change the dimensions of the data to make it more suitable for analysis, improve computational performance, or prepare it for visualization.
-
how to use the various method Polars offers, such as
df.pivot()
,df.unpivot()
,df.transpose()
,df.explode()
, anddf.partition_by()
.
Wide Versus Long DataFrames
Wide DataFrames have many columns and few rows. The idea is that every row contains a column with an identifier, and the data is spread over many columns. This format is often used when there are multiple measurements per observation. An example of wide data would be ...
Get Python Polars: The Definitive Guide now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.