Spaces:
Sleeping
Sleeping
keeping only code cell for examples
Browse filesCo-authored-by: Akshay Agrawal <[email protected]>
- polars/01_why_polars.py +0 -23
polars/01_why_polars.py
CHANGED
@@ -58,29 +58,6 @@ def _(mo):
|
|
58 |
Polars' syntax is similar to PySpark and intuitive like SQL, making heavy use of **method chaining**. This makes it easy for data professionals to transition to Polars, and leads to an API that is more concise and readable than Pandas.
|
59 |
|
60 |
**Example.** In the next few cells, we contrast the code to perform a basic filter and aggregation of data with Pandas to the code required to accomplish the same task with `Polars`.
|
61 |
-
|
62 |
-
**Example: Filtering and Aggregating Data**
|
63 |
-
|
64 |
-
```python
|
65 |
-
import pandas as pd
|
66 |
-
|
67 |
-
df_pd = pd.DataFrame(
|
68 |
-
{
|
69 |
-
"Gender": ["Male", "Female", "Male", "Female", "Male", "Female",
|
70 |
-
"Male", "Female", "Male", "Female"],
|
71 |
-
"Age": [13, 15, 17, 19, 21, 23, 25, 27, 29, 31],
|
72 |
-
"Height_CM": [150.0, 170.0, 146.5, 142.0, 155.0, 165.0, 170.8, 130.0, 132.5, 162.0]
|
73 |
-
}
|
74 |
-
)
|
75 |
-
|
76 |
-
# query: average height of male and female after the age of 15 years
|
77 |
-
|
78 |
-
# step-1: filter
|
79 |
-
filtered_df_pd = df_pd[df_pd["Age"] > 15]
|
80 |
-
|
81 |
-
# step-2: groupby and aggregation
|
82 |
-
result_pd = filtered_df_pd.groupby("Gender")["Height_CM"].mean()
|
83 |
-
```
|
84 |
"""
|
85 |
)
|
86 |
return
|
|
|
58 |
Polars' syntax is similar to PySpark and intuitive like SQL, making heavy use of **method chaining**. This makes it easy for data professionals to transition to Polars, and leads to an API that is more concise and readable than Pandas.
|
59 |
|
60 |
**Example.** In the next few cells, we contrast the code to perform a basic filter and aggregation of data with Pandas to the code required to accomplish the same task with `Polars`.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
61 |
"""
|
62 |
)
|
63 |
return
|