Skip to content

Commit 58a0162

Browse files
Merge branch 'master' into create-django-project
2 parents 00fd9c7 + 0e25d33 commit 58a0162

File tree

12 files changed

+120
-0
lines changed

12 files changed

+120
-0
lines changed

narwhals-python/README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Writing DataFrame-Agnostic Python Code With Narwhals
2+
3+
This folder contains the downloadable code from the Real Python tutorial: [Writing DataFrame-Agnostic Python Code With Narwhals](https://realpython.com/narwhals-python/).
4+
5+
| File | Description |
6+
|---------------------------|-----------------------------------------------------|
7+
| `presidents.parquet` | Data for main sections of the tutorial |
8+
| `universal_processing.py` | Functions used in the main sections of the tutorial |
9+
| `authors.parquet` | Data for the self study section of the tutorial |
10+
| `books.parquet` | Data for the self study section of the tutorial |
11+
| `exercise_solution.py` | A possible solution to the self study exercise |

narwhals-python/authors.parquet

2.73 KB
Binary file not shown.

narwhals-python/books.parquet

4.13 KB
Binary file not shown.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import narwhals as nw
2+
from narwhals.typing import IntoFrameT
3+
4+
5+
def rowling_books(df: IntoFrameT, lf: IntoFrameT) -> IntoFrameT:
6+
return (
7+
nw.from_native(df)
8+
.join(
9+
nw.from_native(lf)
10+
.filter(nw.col("last_name").str.contains("Rowling"))
11+
.collect(),
12+
on="author_id",
13+
)
14+
.select(["book_title", "year_published", "first_name", "last_name"])
15+
.sort("year_published")
16+
.to_pandas()
17+
)

narwhals-python/presidents.parquet

3.32 KB
Binary file not shown.
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import narwhals as nw
2+
from narwhals.typing import FrameT, IntoFrameT
3+
4+
5+
def universal_groupby_v1(df: IntoFrameT) -> IntoFrameT:
6+
return (
7+
nw.from_native(df)
8+
.group_by("party_name")
9+
.agg(nw.col("last_name").count())
10+
.sort("party_name")
11+
.to_native()
12+
)
13+
14+
15+
@nw.narwhalify
16+
def universal_groupby_v2(df: FrameT) -> FrameT:
17+
return (
18+
df.group_by("party_name")
19+
.agg(nw.col("last_name").count())
20+
.sort("party_name")
21+
)
22+
23+
24+
def universal_groupby_v3(df: IntoFrameT) -> IntoFrameT:
25+
return (
26+
nw.from_native(df)
27+
.group_by("party_name")
28+
.agg(nw.col("last_name").count())
29+
.sort("party_name")
30+
.to_polars()
31+
)
32+
33+
34+
def universal_pivot_v1(df: IntoFrameT) -> IntoFrameT:
35+
return (
36+
nw.from_native(df)
37+
.pivot(
38+
on="party_name",
39+
index="century",
40+
values="last_name",
41+
aggregate_function="count",
42+
)
43+
.to_native()
44+
)
45+
46+
47+
def universal_pivot_v2(df: IntoFrameT) -> IntoFrameT:
48+
df = nw.from_native(df)
49+
if isinstance(df, nw.LazyFrame):
50+
df = df.collect()
51+
return df.pivot(
52+
on="party_name",
53+
index="century",
54+
values="last_name",
55+
aggregate_function="count",
56+
).to_native()
38.3 KB
Binary file not shown.

python-skills/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# How to Build the Python Skills That Get You Hired
2+
3+
This folder contains supporting materials for the Real Python tutorial [How to Build the Python Skills That Get You Hired](https://realpython.com/python-skills/).

quantum-computing-basics/README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Quantum Computing Basics With Qiskit
2+
3+
Code examples for the Real Python tutorial on [Quantum Computing Basics With Qiskit](https://realpython.com/quantum-computing-basics/).
4+
5+
## Requirements
6+
7+
- Python 3.10+
8+
- Dependencies from `pyproject.toml`
9+
10+
## Running the Examples
11+
12+
You can use uv to run the main example, which creates a simple quantum circuit with a Hadamard gate and measurement:
13+
14+
```sh
15+
$ uv run quantum_circuit.py
16+
```
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[project]
2+
name = "quantum-computing-basics"
3+
version = "0.1.0"
4+
requires-python = ">=3.10"
5+
dependencies = [
6+
"qiskit[visualization]==2.2.3"
7+
]

0 commit comments

Comments
 (0)