Skip to content

Polars

1
2
# Install the opendal and polars
!pip install opendal, polars
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
import polars as pl

import opendal

# Init an operator.
op = opendal.Operator("fs", root="/tmp")

# Create a DataFrame.
df = pl.DataFrame({"name": ["Alice", "Bob"], "age": [20, 30]})
print(f"df: {df}")

# Open and write the DataFrame to the file.
with op.open("test.csv", mode="wb") as file:
    df.write_csv(file)

# Open and read the DataFrame from the file.
with op.open("test.csv", mode="rb") as file:
    read_df = pl.read_csv(file)
    print(f"read_df: {read_df}")