# Polars Dataframe Library

## Some useful tips about polars dataframe library

### Using SQL queries inside polars

```python
res = pl.SQLContext(frame=df).execute(
"""
with cte as (
  SELECT customer_id, primary_term, final_term from frame where primary_term > final_term limit 100
)
select * from cte order by primary_term desc limit 10
"""
)
res.collect()
```

### Polars basic

{% embed url="<https://github.com/gautamnaik1994/2023-Pycon-Polars>" %}

{% @github-files/github-code-block url="<https://github.com/gautamnaik1994/2023-Pycon-Polars>" %}

#### Timedelta equivalent for Polars

```python
df=df.with_columns(
    pl.col("created_at").dt.offset_by('-5h30m'),
    pl.col("actual_delivery_time").dt.offset_by('-5h30m')
)
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://gautamnaik1994.gitbook.io/snippets/data-science/polars-dataframe-library.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
