Files
Obsidian-Main/20.01. Programming/Python/Polars.md

1.7 KiB
Raw Blame History

tags, aliases, date, time, description
tags aliases date time description
2024-11-10 16:57:31

可以用來代替pandas

Now, listen up-the thing is, Pandas is great at data exploration and for middle-sized datasets. But people just use it for everything, like its some magic solution thats going to solve every problem in data, and quite frankly, it isnt. Working with Pandas on huge datasets can turn your machine into a sputtering fan engine, and memory overhead just doesnt make sense for some workflows.

Why pandas Is Overrated:

Memory Usage: As Pandas operates mainly in-memory, any operation on a large dataset will badly hit performance.

Limited Scalability: Scaling with Pandas isnt easy. It was never designed for big data.

What You Should Use Instead: Polars

Polars is an ultra-fast DataFrame library in Rust using Apache Arrow. Optimized for memory efficiency and multithreaded performance, this makes it perfect for when you want to crunch data without heating up your CPU.

import polars as pl  
  
df = pl.read_csv("big_data.csv")  
filtered_df = df.filter(pl.col("value") > 50)  
print(filtered_df)

Why **Polars**? It will process data that would bring Pandas to its knees, and it handles operations in a fraction of the time. Besides that, it also has lazy evaluation-meaning it is only computing whats needed.

參考來源