Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 16 additions & 10 deletions pandas-fast-flexible-intuitive/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,15 @@ Corresponding data for ["Fast, Flexible, Easy and Intuitive: How to Speed Up You

## Running the Script

Install the pinned dependencies first:

```bash
$ python -m pip install -r requirements.txt
```

The module `tutorial/__main__.py` is the script that mimics the tutorial code. A `__main__.py` script has the effect of executing when the containing package is run as `python -m <packagename>`.

Here is an example output (MacBook Pro, 3.1 GHz Intel Core i5):
Here is an example output (Python 3.14, pandas 3.0.6):

```bash
pandas-fast-flexible-intuitive$ python3 -m tutorial
Expand All @@ -17,32 +23,32 @@ Companion code to https://realpython.com/fast-flexible-pandas.
Note: most of the functions here modify a Pandas DataFrame in-place,
which is generally not great practice but used with caution here.

Python version: 3.6.6
Pandas version: 0.23.2
Python version: 3.14.6
Pandas version: 3.0.6

Timing code ...

Best of 3 trials with 10 function calls per trial:
Function `convert` ran in average of 1.348 seconds.
Function `convert` ran in average of 0.374 seconds.

Best of 3 trials with 100 function calls per trial:
Function `convert_with_format` ran in average of 0.025 seconds.
Function `convert_with_format` ran in average of 0.018 seconds.

Best of 2 trials with 10 function calls per trial:
Function `apply_tariff_loop` ran in average of 3.313 seconds.
Function `apply_tariff_loop` ran in average of 1.338 seconds.

Best of 3 trials with 50 function calls per trial:
Function `apply_tariff_iterrows` ran in average of 0.650 seconds.
Function `apply_tariff_iterrows` ran in average of 0.326 seconds.

Best of 3 trials with 100 function calls per trial:
Function `apply_tariff_withapply` ran in average of 0.202 seconds.
Function `apply_tariff_withapply` ran in average of 0.067 seconds.

Best of 3 trials with 1000 function calls per trial:
Function `apply_tariff_isin` ran in average of 0.004 seconds.
Function `apply_tariff_isin` ran in average of 0.003 seconds.

Best of 3 trials with 1000 function calls per trial:
Function `apply_tariff_cut` ran in average of 0.001 seconds.

Best of 3 trials with 1000 function calls per trial:
Function `apply_tariff_digitize` ran in average of 0.001 seconds.
Function `apply_tariff_digitize` ran in average of 0.000 seconds.
```
2 changes: 2 additions & 0 deletions pandas-fast-flexible-intuitive/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
numpy==2.5.3
pandas==3.0.6
2 changes: 1 addition & 1 deletion pandas-fast-flexible-intuitive/tutorial/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from .timer import timeit


# Two functions for conversion of object dtype to datetime
# Two functions for conversion of str dtype to datetime
# Note that you could also specify `parse_dates` within `pd.read_csv()`
@timeit(repeat=3, number=10)
def convert(df, column_name):
Expand Down
Loading