Spaces:
Running
Running
keeping only code cell for examples
Browse filesCo-authored-by: Akshay Agrawal <[email protected]>
- polars/01_why_polars.py +0 -17
polars/01_why_polars.py
CHANGED
@@ -124,23 +124,6 @@ def _(mo):
|
|
124 |
Notice how Polars uses a *method-chaining* approach, similar to PySpark, which makes the code more readable and expressive while using a *single line* to design the query.
|
125 |
|
126 |
Additionally, Polars supports SQL-like operations *natively*, that allows you to write SQL queries directly on polars dataframe:
|
127 |
-
|
128 |
-
```python
|
129 |
-
import polars as pl
|
130 |
-
|
131 |
-
df_pl = pl.DataFrame(
|
132 |
-
{
|
133 |
-
"Gender": ["Male", "Female", "Male", "Female", "Male", "Female",
|
134 |
-
"Male", "Female", "Male", "Female"],
|
135 |
-
"Age": [13, 15, 17, 19, 21, 23, 25, 27, 29, 31],
|
136 |
-
"Height_CM": [150.0, 170.0, 146.5, 142.0, 155.0, 165.0, 170.8, 130.0, 132.5, 162.0]
|
137 |
-
}
|
138 |
-
)
|
139 |
-
|
140 |
-
# query: average height of male and female after the age of 15 years
|
141 |
-
result = df_pl.sql("SELECT Gender, AVG(Height_CM) FROM self WHERE Age > 15 GROUP BY Gender")
|
142 |
-
result
|
143 |
-
```
|
144 |
"""
|
145 |
)
|
146 |
return
|
|
|
124 |
Notice how Polars uses a *method-chaining* approach, similar to PySpark, which makes the code more readable and expressive while using a *single line* to design the query.
|
125 |
|
126 |
Additionally, Polars supports SQL-like operations *natively*, that allows you to write SQL queries directly on polars dataframe:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
127 |
"""
|
128 |
)
|
129 |
return
|