Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Lære Basic Data Operations in Polars | Efficient Data Manipulation with Polars
Large Data Handling

Basic Data Operations in Polars

Sveip for å vise menyen

When you work with large datasets, efficient data manipulation is essential. The polars library is designed for high-performance data operations, making it a popular choice for handling large data in Python. In this chapter, you will learn how to load data, select specific columns, and filter rows using polars. These basic actions form the foundation for more complex data transformations.

The table below summarizes the main functions in polars for performing these basic operations.

1234567
import polars as pl # Read data from a CSV file df = pl.read_csv("data/people.csv") # Display the first 5 rows print(df.head())

In this code, you import the polars library and use the pl.read_csv() function to load data from a file named "data/people.csv". The resulting DataFrame is stored in the variable df. By calling df.head(), you can view the first five rows of the DataFrame, which is useful to quickly inspect your data after loading.

123456789
import polars as pl # Load the dataset df = pl.read_csv("data/people.csv") # Select the "name" and "age" columns selected = df.select(["name", "age"]) print(selected)

Here, you use the select() method to choose only the "name" and "age" columns from the DataFrame. This creates a new DataFrame called selected containing just those columns. Selecting columns is a common operation when you want to focus on specific parts of your data for further analysis.

question mark

Which method is used to read a CSV file in polars?

Velg det helt riktige svaret

Alt var klart?

Hvordan kan vi forbedre det?

Takk for tilbakemeldingene dine!

Seksjon 3. Kapittel 2

Spør AI

expand

Spør AI

ChatGPT

Spør om hva du vil, eller prøv ett av de foreslåtte spørsmålene for å starte chatten vår

Seksjon 3. Kapittel 2
some-alt