Skip to content

Commit c02d9ea

Browse files
authored
Merge branch 'master' into how-to-write-claudemd-file
2 parents 62e4a77 + 011734e commit c02d9ea

59 files changed

Lines changed: 1270 additions & 105 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

data-analysis/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Using Python for Data Analysis
22

3-
This folder contains completed notebooks and other files used in the Real Python tutorial on [Using Python for Data Analysis](https://realpython.com/python-for-data-analysis/).
3+
This folder contains completed notebooks and other files used in the Real Python tutorial [Python for Data Analysis: A Practical Guide](https://realpython.com/python-for-data-analysis/).
44

55
**The following files are included:**
66

data-analysis/data_analysis_findings.ipynb

Lines changed: 35 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,8 @@
166166
"import pandas as pd\n",
167167
"\n",
168168
"james_bond_data_html = pd.read_html(\n",
169-
" \"https://en.wikipedia.org/wiki/List_of_James_Bond_novels_and_short_stories\"\n",
169+
" \"https://en.wikipedia.org/wiki/List_of_James_Bond_novels_and_short_stories\",\n",
170+
" storage_options={\"User-Agent\": \"Mozilla/5.0\"},\n",
170171
")\n",
171172
"james_bond_tables = james_bond_data_html[1].convert_dtypes()"
172173
]
@@ -305,7 +306,7 @@
305306
" .assign(\n",
306307
" income_usa=lambda data: (\n",
307308
" data[\"income_usa\"]\n",
308-
" .replace(\"[$,]\", \"\", regex=True)\n",
309+
" .replace(r\"[$,\\s]\", \"\", regex=True)\n",
309310
" .astype(\"Float64\")\n",
310311
" ),\n",
311312
" )\n",
@@ -327,17 +328,17 @@
327328
" .assign(\n",
328329
" income_usa=lambda data: (\n",
329330
" data[\"income_usa\"]\n",
330-
" .replace(\"[$,]\", \"\", regex=True)\n",
331+
" .replace(r\"[$,\\s]\", \"\", regex=True)\n",
331332
" .astype(\"Float64\")\n",
332333
" ),\n",
333334
" income_world=lambda data: (\n",
334335
" data[\"income_world\"]\n",
335-
" .replace(\"[$,]\", \"\", regex=True)\n",
336+
" .replace(r\"[$,\\s]\", \"\", regex=True)\n",
336337
" .astype(\"Float64\")\n",
337338
" ),\n",
338339
" movie_budget=lambda data: (\n",
339340
" data[\"movie_budget\"]\n",
340-
" .replace(\"[$,]\", \"\", regex=True)\n",
341+
" .replace(r\"[$,\\s]\", \"\", regex=True)\n",
341342
" .astype(\"Float64\")\n",
342343
" ),\n",
343344
" )\n",
@@ -367,21 +368,21 @@
367368
" .assign(\n",
368369
" income_usa=lambda data: (\n",
369370
" data[\"income_usa\"]\n",
370-
" .replace(\"[$,]\", \"\", regex=True)\n",
371+
" .replace(r\"[$,\\s]\", \"\", regex=True)\n",
371372
" .astype(\"Float64\")\n",
372373
" ),\n",
373374
" income_world=lambda data: (\n",
374375
" data[\"income_world\"]\n",
375-
" .replace(\"[$,]\", \"\", regex=True)\n",
376+
" .replace(r\"[$,\\s]\", \"\", regex=True)\n",
376377
" .astype(\"Float64\")\n",
377378
" ),\n",
378379
" movie_budget=lambda data: (\n",
379380
" data[\"movie_budget\"]\n",
380-
" .replace(\"[$,]\", \"\", regex=True)\n",
381+
" .replace(r\"[$,\\s]\", \"\", regex=True)\n",
381382
" .astype(\"Float64\")\n",
382383
" ),\n",
383384
" film_length=lambda data: (\n",
384-
" data[\"film_length\"].str.removesuffix(\"mins\").astype(\"Int64\")\n",
385+
" data[\"film_length\"].str.removesuffix(\" mins\").astype(\"Int64\")\n",
385386
" ),\n",
386387
" )\n",
387388
")"
@@ -442,21 +443,21 @@
442443
" .assign(\n",
443444
" income_usa=lambda data: (\n",
444445
" data[\"income_usa\"]\n",
445-
" .replace(\"[$,]\", \"\", regex=True)\n",
446+
" .replace(r\"[$,\\s]\", \"\", regex=True)\n",
446447
" .astype(\"Float64\")\n",
447448
" ),\n",
448449
" income_world=lambda data: (\n",
449450
" data[\"income_world\"]\n",
450-
" .replace(\"[$,]\", \"\", regex=True)\n",
451+
" .replace(r\"[$,\\s]\", \"\", regex=True)\n",
451452
" .astype(\"Float64\")\n",
452453
" ),\n",
453454
" movie_budget=lambda data: (\n",
454455
" data[\"movie_budget\"]\n",
455-
" .replace(\"[$,]\", \"\", regex=True)\n",
456+
" .replace(r\"[$,\\s]\", \"\", regex=True)\n",
456457
" .astype(\"Float64\")\n",
457458
" ),\n",
458459
" film_length=lambda data: (\n",
459-
" data[\"film_length\"].str.removesuffix(\"mins\").astype(\"Int64\")\n",
460+
" data[\"film_length\"].str.removesuffix(\" mins\").astype(\"Int64\")\n",
460461
" ),\n",
461462
" release_date=lambda data: pd.to_datetime(\n",
462463
" data[\"release_date\"], format=\"%B, %Y\"\n",
@@ -529,22 +530,22 @@
529530
" .assign(\n",
530531
" income_usa=lambda data: (\n",
531532
" data[\"income_usa\"]\n",
532-
" .replace(\"[$,]\", \"\", regex=True)\n",
533+
" .replace(r\"[$,\\s]\", \"\", regex=True)\n",
533534
" .astype(\"Float64\")\n",
534535
" ),\n",
535536
" income_world=lambda data: (\n",
536537
" data[\"income_world\"]\n",
537-
" .replace(\"[$,]\", \"\", regex=True)\n",
538+
" .replace(r\"[$,\\s]\", \"\", regex=True)\n",
538539
" .astype(\"Float64\")\n",
539540
" ),\n",
540541
" movie_budget=lambda data: (\n",
541542
" data[\"movie_budget\"]\n",
542-
" .replace(\"[$,]\", \"\", regex=True)\n",
543+
" .replace(r\"[$,\\s]\", \"\", regex=True)\n",
543544
" .astype(\"Float64\")\n",
544545
" * 1000\n",
545546
" ),\n",
546547
" film_length=lambda data: (\n",
547-
" data[\"film_length\"].str.removesuffix(\"mins\").astype(\"Int64\")\n",
548+
" data[\"film_length\"].str.removesuffix(\" mins\").astype(\"Int64\")\n",
548549
" ),\n",
549550
" release_date=lambda data: pd.to_datetime(\n",
550551
" data[\"release_date\"], format=\"%B, %Y\"\n",
@@ -597,22 +598,22 @@
597598
" .assign(\n",
598599
" income_usa=lambda data: (\n",
599600
" data[\"income_usa\"]\n",
600-
" .replace(\"[$,]\", \"\", regex=True)\n",
601+
" .replace(r\"[$,\\s]\", \"\", regex=True)\n",
601602
" .astype(\"Float64\")\n",
602603
" ),\n",
603604
" income_world=lambda data: (\n",
604605
" data[\"income_world\"]\n",
605-
" .replace(\"[$,]\", \"\", regex=True)\n",
606+
" .replace(r\"[$,\\s]\", \"\", regex=True)\n",
606607
" .astype(\"Float64\")\n",
607608
" ),\n",
608609
" movie_budget=lambda data: (\n",
609610
" data[\"movie_budget\"]\n",
610-
" .replace(\"[$,]\", \"\", regex=True)\n",
611+
" .replace(r\"[$,\\s]\", \"\", regex=True)\n",
611612
" .astype(\"Float64\")\n",
612613
" * 1000\n",
613614
" ),\n",
614615
" film_length=lambda data: (\n",
615-
" data[\"film_length\"].str.removesuffix(\"mins\").astype(\"Int64\")\n",
616+
" data[\"film_length\"].str.removesuffix(\" mins\").astype(\"Int64\")\n",
616617
" ),\n",
617618
" release_date=lambda data: pd.to_datetime(\n",
618619
" data[\"release_date\"], format=\"%B, %Y\"\n",
@@ -662,22 +663,22 @@
662663
" .assign(\n",
663664
" income_usa=lambda data: (\n",
664665
" data[\"income_usa\"]\n",
665-
" .replace(\"[$,]\", \"\", regex=True)\n",
666+
" .replace(r\"[$,\\s]\", \"\", regex=True)\n",
666667
" .astype(\"Float64\")\n",
667668
" ),\n",
668669
" income_world=lambda data: (\n",
669670
" data[\"income_world\"]\n",
670-
" .replace(\"[$,]\", \"\", regex=True)\n",
671+
" .replace(r\"[$,\\s]\", \"\", regex=True)\n",
671672
" .astype(\"Float64\")\n",
672673
" ),\n",
673674
" movie_budget=lambda data: (\n",
674675
" data[\"movie_budget\"]\n",
675-
" .replace(\"[$,]\", \"\", regex=True)\n",
676+
" .replace(r\"[$,\\s]\", \"\", regex=True)\n",
676677
" .astype(\"Float64\")\n",
677678
" * 1000\n",
678679
" ),\n",
679680
" film_length=lambda data: (\n",
680-
" data[\"film_length\"].str.removesuffix(\"mins\").astype(\"Int64\")\n",
681+
" data[\"film_length\"].str.removesuffix(\" mins\").astype(\"Int64\")\n",
681682
" ),\n",
682683
" release_date=lambda data: pd.to_datetime(\n",
683684
" data[\"release_date\"], format=\"%B, %Y\"\n",
@@ -738,23 +739,23 @@
738739
" .assign(\n",
739740
" income_usa=lambda data: (\n",
740741
" data[\"income_usa\"]\n",
741-
" .replace(\"[$,]\", \"\", regex=True)\n",
742+
" .replace(r\"[$,\\s]\", \"\", regex=True)\n",
742743
" .astype(\"Float64\")\n",
743744
" ),\n",
744745
" income_world=lambda data: (\n",
745746
" data[\"income_world\"]\n",
746-
" .replace(\"[$,]\", \"\", regex=True)\n",
747+
" .replace(r\"[$,\\s]\", \"\", regex=True)\n",
747748
" .astype(\"Float64\")\n",
748749
" ),\n",
749750
" movie_budget=lambda data: (\n",
750751
" data[\"movie_budget\"]\n",
751-
" .replace(\"[$,]\", \"\", regex=True)\n",
752+
" .replace(r\"[$,\\s]\", \"\", regex=True)\n",
752753
" .astype(\"Float64\")\n",
753754
" * 1000\n",
754755
" ),\n",
755756
" film_length=lambda data: (\n",
756757
" data[\"film_length\"]\n",
757-
" .str.removesuffix(\"mins\")\n",
758+
" .str.removesuffix(\" mins\")\n",
758759
" .astype(\"Int64\")\n",
759760
" .replace(1200, 120)\n",
760761
" ),\n",
@@ -820,23 +821,23 @@
820821
" .assign(\n",
821822
" income_usa=lambda data: (\n",
822823
" data[\"income_usa\"]\n",
823-
" .replace(\"[$,]\", \"\", regex=True)\n",
824+
" .replace(r\"[$,\\s]\", \"\", regex=True)\n",
824825
" .astype(\"Float64\")\n",
825826
" ),\n",
826827
" income_world=lambda data: (\n",
827828
" data[\"income_world\"]\n",
828-
" .replace(\"[$,]\", \"\", regex=True)\n",
829+
" .replace(r\"[$,\\s]\", \"\", regex=True)\n",
829830
" .astype(\"Float64\")\n",
830831
" ),\n",
831832
" movie_budget=lambda data: (\n",
832833
" data[\"movie_budget\"]\n",
833-
" .replace(\"[$,]\", \"\", regex=True)\n",
834+
" .replace(r\"[$,\\s]\", \"\", regex=True)\n",
834835
" .astype(\"Float64\")\n",
835836
" * 1000\n",
836837
" ),\n",
837838
" film_length=lambda data: (\n",
838839
" data[\"film_length\"]\n",
839-
" .str.removesuffix(\"mins\")\n",
840+
" .str.removesuffix(\" mins\")\n",
840841
" .astype(\"Int64\")\n",
841842
" .replace(1200, 120)\n",
842843
" ),\n",
@@ -1059,7 +1060,7 @@
10591060
"name": "python",
10601061
"nbconvert_exporter": "python",
10611062
"pygments_lexer": "ipython3",
1062-
"version": "3.12.0"
1063+
"version": "3.14.5"
10631064
}
10641065
},
10651066
"nbformat": 4,

data-analysis/data_analysis_results.ipynb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,23 +54,23 @@
5454
" .assign(\n",
5555
" income_usa=lambda data: (\n",
5656
" data[\"income_usa\"]\n",
57-
" .replace(\"[$,]\", \"\", regex=True)\n",
57+
" .replace(r\"[$,\\s]\", \"\", regex=True)\n",
5858
" .astype(\"Float64\")\n",
5959
" ),\n",
6060
" income_world=lambda data: (\n",
6161
" data[\"income_world\"]\n",
62-
" .replace(\"[$,]\", \"\", regex=True)\n",
62+
" .replace(r\"[$,\\s]\", \"\", regex=True)\n",
6363
" .astype(\"Float64\")\n",
6464
" ),\n",
6565
" movie_budget=lambda data: (\n",
6666
" data[\"movie_budget\"]\n",
67-
" .replace(\"[$,]\", \"\", regex=True)\n",
67+
" .replace(r\"[$,\\s]\", \"\", regex=True)\n",
6868
" .astype(\"Float64\")\n",
6969
" * 1000\n",
7070
" ),\n",
7171
" film_length=lambda data: (\n",
7272
" data[\"film_length\"]\n",
73-
" .str.removesuffix(\"mins\")\n",
73+
" .str.removesuffix(\" mins\")\n",
7474
" .astype(\"Int64\")\n",
7575
" .replace(1200, 120)\n",
7676
" ),\n",
@@ -231,7 +231,7 @@
231231
"name": "python",
232232
"nbconvert_exporter": "python",
233233
"pygments_lexer": "ipython3",
234-
"version": "3.12.0"
234+
"version": "3.14.5"
235235
}
236236
},
237237
"nbformat": 4,
Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
1-
bond_actor,bond_kills,car_manufacturer,film_length,imdb,income_usa,income_world,martinis_consumed,movie_budget,movie_title,release_date,rotten_tomatoes,release_year
2-
Sean Connery,4,Sunbeam,110,7.3,16067035.0,59567035.0,2,1000000.0,Dr. No,1962-06-01,7.7,1962
3-
Sean Connery,11,Bentley,115,7.5,24800000.0,78900000.0,0,2000000.0,From Russia with Love,1963-08-01,8.0,1963
4-
Sean Connery,9,Aston Martin,110,7.8,51100000.0,124900000.0,1,3000000.0,Goldfinger,1964-05-01,8.4,1964
5-
Sean Connery,20,Aston Martin,130,7.0,63600000.0,141200000.0,0,9000000.0,Thunderball,1965-09-01,6.8,1965
6-
Sean Connery,21,Toyota,117,6.9,43100000.0,111600000.0,1,9500000.0,You Only Live Twice,1967-11-01,6.3,1967
7-
George Lazenby,5,Mercury,142,6.8,22800000.0,82000000.0,1,8000000.0,On Her Majesty's Secret Service,1969-07-01,6.7,1969
8-
Sean Connery,7,Ford,120,6.7,43800000.0,116000000.0,0,7200000.0,Diamonds Are Forever,1971-03-01,6.3,1971
9-
Roger Moore,8,AMC,121,6.8,35400000.0,161800000.0,0,7000000.0,Live and Let Die,1973-08-01,5.9,1973
10-
Roger Moore,1,AMC,125,6.7,21000000.0,97600000.0,0,7000000.0,The Man with the Golden Gun,1974-07-01,5.1,1974
11-
Roger Moore,31,Lotus,125,7.1,46800000.0,185400000.0,1,14000000.0,The Spy Who Loved Me,1977-04-01,6.8,1977
12-
Roger Moore,12,Lotus,126,6.2,70300000.0,210300000.0,1,31000000.0,Moonraker,1979-10-01,5.7,1979
13-
Roger Moore,18,Citroen,127,6.8,54800000.0,195300000.0,0,28000000.0,For Your Eyes Only,1981-06-01,6.3,1981
14-
Roger Moore,15,Bajaj,131,6.5,67900000.0,187500000.0,0,27500000.0,Octopussy,1983-03-01,5.3,1983
15-
Roger Moore,5,Rolls Royce,131,6.2,50327960.0,152627960.0,0,30000000.0,A View to a Kill,1985-10-01,4.7,1985
16-
Timothy Dalton,13,Rolls Royce,130,6.7,51185000.0,191200000.0,2,40000000.0,The Living Daylights,1987-05-01,6.3,1987
17-
Timothy Dalton,10,Aston Martin,133,6.5,34667015.0,156167015.0,1,42000000.0,License to Kill,1989-01-01,6.0,1989
18-
Pierce Brosnan,47,BMW,130,7.2,106429941.0,356429941.0,1,60000000.0,GoldenEye,1995-09-01,6.9,1995
19-
Pierce Brosnan,30,Aston Martin,119,6.4,125304276.0,339504276.0,1,110000000.0,Tomorrow Never Dies,1997-07-01,6.0,1997
20-
Pierce Brosnan,27,BMW,128,6.3,126930660.0,361730660.0,1,135000000.0,The World Is Not Enough,1999-06-01,5.7,1999
21-
Pierce Brosnan,31,Aston Martin,133,6.0,160942139.0,431942139.0,2,142000000.0,Die Another Day,2002-08-01,6.1,2002
22-
Daniel Craig,11,Aston Martin,144,7.9,167365000.0,596365000.0,3,102000000.0,Casino Royale,2006-02-01,7.8,2006
23-
Daniel Craig,16,Aston Martin,106,6.7,169368427.0,591692078.0,6,230000000.0,Quantum of Solace,2008-12-01,6.1,2008
24-
Daniel Craig,26,Aston Martin,143,7.8,304360277.0,1108561108.0,1,200000000.0,Skyfall,2012-11-01,8.2,2012
25-
Daniel Craig,30,Aston Martin,148,6.8,200074175.0,879620923.0,1,245000000.0,Spectre,2015-09-01,6.4,2015
26-
Daniel Craig,14,Aston Martin,163,7.3,160891007.0,759959662.0,1,275000000.0,No Time to Die,2021-11-01,7.3,2021
1+
release_date,movie_title,bond_actor,car_manufacturer,income_usa,income_world,movie_budget,film_length,imdb,rotten_tomatoes,martinis_consumed,bond_kills,release_year
2+
1962-06-01,Dr. No,Sean Connery,Sunbeam,16067035.0,59567035.0,1000000.0,110,7.3,7.7,2,4,1962
3+
1963-08-01,From Russia with Love,Sean Connery,Bentley,24800000.0,78900000.0,2000000.0,115,7.5,8.0,0,11,1963
4+
1964-05-01,Goldfinger,Sean Connery,Aston Martin,51100000.0,124900000.0,3000000.0,110,7.8,8.4,1,9,1964
5+
1965-09-01,Thunderball,Sean Connery,Aston Martin,63600000.0,141200000.0,9000000.0,130,7.0,6.8,0,20,1965
6+
1967-11-01,You Only Live Twice,Sean Connery,Toyota,43100000.0,111600000.0,9500000.0,117,6.9,6.3,1,21,1967
7+
1969-07-01,On Her Majesty's Secret Service,George Lazenby,Mercury,22800000.0,82000000.0,8000000.0,142,6.8,6.7,1,5,1969
8+
1971-03-01,Diamonds Are Forever,Sean Connery,Ford,43800000.0,116000000.0,7200000.0,120,6.7,6.3,0,7,1971
9+
1973-08-01,Live and Let Die,Roger Moore,AMC,35400000.0,161800000.0,7000000.0,121,6.8,5.9,0,8,1973
10+
1974-07-01,The Man with the Golden Gun,Roger Moore,AMC,21000000.0,97600000.0,7000000.0,125,6.7,5.1,0,1,1974
11+
1977-04-01,The Spy Who Loved Me,Roger Moore,Lotus,46800000.0,185400000.0,14000000.0,125,7.1,6.8,1,31,1977
12+
1979-10-01,Moonraker,Roger Moore,Lotus,70300000.0,210300000.0,31000000.0,126,6.2,5.7,1,12,1979
13+
1981-06-01,For Your Eyes Only,Roger Moore,Citroen,54800000.0,195300000.0,28000000.0,127,6.8,6.3,0,18,1981
14+
1983-03-01,Octopussy,Roger Moore,Bajaj,67900000.0,187500000.0,27500000.0,131,6.5,5.3,0,15,1983
15+
1985-10-01,A View to a Kill,Roger Moore,Rolls Royce,50327960.0,152627960.0,30000000.0,131,6.2,4.7,0,5,1985
16+
1987-05-01,The Living Daylights,Timothy Dalton,Rolls Royce,51185000.0,191200000.0,40000000.0,130,6.7,6.3,2,13,1987
17+
1989-01-01,License to Kill,Timothy Dalton,Aston Martin,34667015.0,156167015.0,42000000.0,133,6.5,6.0,1,10,1989
18+
1995-09-01,GoldenEye,Pierce Brosnan,BMW,106429941.0,356429941.0,60000000.0,130,7.2,6.9,1,47,1995
19+
1997-07-01,Tomorrow Never Dies,Pierce Brosnan,Aston Martin,125304276.0,339504276.0,110000000.0,119,6.4,6.0,1,30,1997
20+
1999-06-01,The World Is Not Enough,Pierce Brosnan,BMW,126930660.0,361730660.0,135000000.0,128,6.3,5.7,1,27,1999
21+
2002-08-01,Die Another Day,Pierce Brosnan,Aston Martin,160942139.0,431942139.0,142000000.0,133,6.0,6.1,2,31,2002
22+
2006-02-01,Casino Royale,Daniel Craig,Aston Martin,167365000.0,596365000.0,102000000.0,144,7.9,7.8,3,11,2006
23+
2008-12-01,Quantum of Solace,Daniel Craig,Aston Martin,169368427.0,591692078.0,230000000.0,106,6.7,6.1,6,16,2008
24+
2012-11-01,Skyfall,Daniel Craig,Aston Martin,304360277.0,1108561108.0,200000000.0,143,7.8,8.2,1,26,2012
25+
2015-09-01,Spectre,Daniel Craig,Aston Martin,200074175.0,879620923.0,245000000.0,148,6.8,6.4,1,30,2015
26+
2021-11-01,No Time to Die,Daniel Craig,Aston Martin,160891007.0,759959662.0,275000000.0,163,7.3,7.3,1,14,2021

0 commit comments

Comments
 (0)