From 76025f894e8fd4890d3df73e01012edbd2b4d0e9 Mon Sep 17 00:00:00 2001 From: Real Python CMS Agent Date: Mon, 21 Sep 2026 06:19:35 +0000 Subject: [PATCH] Sync pandas-fast-flexible-intuitive with the maintenance update of 'Fast, Flexible, Easy and Intuitive: How to Speed Up Your pandas Projects' --- pandas-fast-flexible-intuitive/README.md | 26 ++++++++++++------- .../requirements.txt | 2 ++ .../tutorial/__main__.py | 2 +- 3 files changed, 19 insertions(+), 11 deletions(-) create mode 100644 pandas-fast-flexible-intuitive/requirements.txt diff --git a/pandas-fast-flexible-intuitive/README.md b/pandas-fast-flexible-intuitive/README.md index a212d0635a..d8566194cf 100644 --- a/pandas-fast-flexible-intuitive/README.md +++ b/pandas-fast-flexible-intuitive/README.md @@ -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 `. -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 @@ -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. ``` diff --git a/pandas-fast-flexible-intuitive/requirements.txt b/pandas-fast-flexible-intuitive/requirements.txt new file mode 100644 index 0000000000..7c32977de0 --- /dev/null +++ b/pandas-fast-flexible-intuitive/requirements.txt @@ -0,0 +1,2 @@ +numpy==2.5.3 +pandas==3.0.6 diff --git a/pandas-fast-flexible-intuitive/tutorial/__main__.py b/pandas-fast-flexible-intuitive/tutorial/__main__.py index 5507ae0b38..7a31053b68 100644 --- a/pandas-fast-flexible-intuitive/tutorial/__main__.py +++ b/pandas-fast-flexible-intuitive/tutorial/__main__.py @@ -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):