File size: 25,694 Bytes
c2522bb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Movie recommendation"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 252,
   "metadata": {},
   "outputs": [],
   "source": [
    "import os \n",
    "import pickle\n",
    "\n",
    "path_data = r\"data/movies\"\n",
    "\n",
    "with open(os.path.join(path_data,'movies_dict.pkl'), 'rb') as file:\n",
    "    movies_data = pickle.load(file)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 253,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "movies = pd.DataFrame(movies_data)\n",
    "movies.drop_duplicates(inplace=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 254,
   "metadata": {},
   "outputs": [],
   "source": [
    "import re\n",
    "\n",
    "def has_capital(string):\n",
    "    for index, char in enumerate(string):\n",
    "        if char.isupper() and index != 0:\n",
    "            return True\n",
    "    return False\n",
    "\n",
    "def clean_tags(text):\n",
    "    pattern1 = re.compile(r'[?!]')\n",
    "    pattern2 = re.compile(r'\\.(?!\\s|$)')\n",
    "    pattern3 = re.compile(r'\\.[a-zA-Z]\\.')\n",
    "    \n",
    "    text_clean = re.sub(pattern1, '. ', text)\n",
    "    text_clean = re.sub(pattern2, \"\", text_clean)\n",
    "    text_clean = re.sub(pattern3, \"\", text_clean)\n",
    "    text_clean = text_clean.replace(\"RobertDowneyJr.\",\"\").replace(\"SamuelL.\",\"\").replace(\"ScienceFiction\", \"Sciencefiction\")\n",
    "\n",
    "    tags_words = \" \".join([t for t in text_clean.split(\" \") if has_capital(t)==False])\n",
    "    tags_words = [t for t in tags_words.split(\". \")[-1:][0].strip().split(\" \")[:8] if t!=\"\"]\n",
    "    tags_words = [t for t in tags_words if t[0].isupper()==True]\n",
    "    #tags_words_clean = [t for t in tags_words_clean if has_capital(t)==False]\n",
    "    return \" \".join(sorted(tags_words)).replace(\"Sciencefiction\",\"Science Fiction\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 255,
   "metadata": {},
   "outputs": [],
   "source": [
    "movies[\"tags\"] = movies[\"tags\"].apply(lambda x: x.replace(\"\",\".\").replace(\"\",\"\").replace(\"  \",\" \"))\n",
    "movies[\"description\"] = movies[\"tags\"].apply(lambda x: \".\".join(x.split(\".\")[:-1] + [\"\"]))\n",
    "movies[\"tags_clean\"] = movies[\"tags\"].apply(clean_tags).apply(lambda x: x.replace(\"Science Fiction\",\"Sciencefiction\"))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 256,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>movie_id</th>\n",
       "      <th>title</th>\n",
       "      <th>tags</th>\n",
       "      <th>description</th>\n",
       "      <th>tags_clean</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>19995</td>\n",
       "      <td>Avatar</td>\n",
       "      <td>In the 22nd century, a paraplegic Marine is di...</td>\n",
       "      <td>In the 22nd century, a paraplegic Marine is di...</td>\n",
       "      <td>Action Adventure Fantasy Sciencefiction</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>285</td>\n",
       "      <td>Pirates of the Caribbean: At World's End</td>\n",
       "      <td>Captain Barbossa, long believed to be dead, ha...</td>\n",
       "      <td>Captain Barbossa, long believed to be dead, ha...</td>\n",
       "      <td>Action Adventure Fantasy</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>206647</td>\n",
       "      <td>Spectre</td>\n",
       "      <td>A cryptic message from Bond’s past sends him o...</td>\n",
       "      <td>A cryptic message from Bond’s past sends him o...</td>\n",
       "      <td>M While</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>49026</td>\n",
       "      <td>The Dark Knight Rises</td>\n",
       "      <td>Following the death of District Attorney Harve...</td>\n",
       "      <td>Following the death of District Attorney Harve...</td>\n",
       "      <td>Action Crime Drama Thriller</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>49529</td>\n",
       "      <td>John Carter</td>\n",
       "      <td>John Carter is a war-weary, former military ca...</td>\n",
       "      <td>John Carter is a war-weary, former military ca...</td>\n",
       "      <td>Action Adventure Sciencefiction</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4804</th>\n",
       "      <td>9367</td>\n",
       "      <td>El Mariachi</td>\n",
       "      <td>El Mariachi just wants to play his guitar and ...</td>\n",
       "      <td>El Mariachi just wants to play his guitar and ...</td>\n",
       "      <td>Action Crime Thriller</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4805</th>\n",
       "      <td>72766</td>\n",
       "      <td>Newlyweds</td>\n",
       "      <td>A newlywed couple's honeymoon is upended by th...</td>\n",
       "      <td>A newlywed couple's honeymoon is upended by th...</td>\n",
       "      <td>Comedy Romance</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4806</th>\n",
       "      <td>231617</td>\n",
       "      <td>Signed, Sealed, Delivered</td>\n",
       "      <td>\"Signed, Sealed, Delivered\" introduces a dedic...</td>\n",
       "      <td>\"Signed, Sealed, Delivered\" introduces a dedic...</td>\n",
       "      <td>Comedy Drama Romance</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4807</th>\n",
       "      <td>126186</td>\n",
       "      <td>Shanghai Calling</td>\n",
       "      <td>When ambitious New York attorney Sam is sent t...</td>\n",
       "      <td>When ambitious New York attorney Sam is sent t...</td>\n",
       "      <td>Anonymous Written</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4808</th>\n",
       "      <td>25975</td>\n",
       "      <td>My Date with Drew</td>\n",
       "      <td>Ever since the second grade when he first saw ...</td>\n",
       "      <td>Ever since the second grade when he first saw ...</td>\n",
       "      <td>Documentary</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>4806 rows × 5 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "      movie_id                                     title  \\\n",
       "0        19995                                    Avatar   \n",
       "1          285  Pirates of the Caribbean: At World's End   \n",
       "2       206647                                   Spectre   \n",
       "3        49026                     The Dark Knight Rises   \n",
       "4        49529                               John Carter   \n",
       "...        ...                                       ...   \n",
       "4804      9367                               El Mariachi   \n",
       "4805     72766                                 Newlyweds   \n",
       "4806    231617                 Signed, Sealed, Delivered   \n",
       "4807    126186                          Shanghai Calling   \n",
       "4808     25975                         My Date with Drew   \n",
       "\n",
       "                                                   tags  \\\n",
       "0     In the 22nd century, a paraplegic Marine is di...   \n",
       "1     Captain Barbossa, long believed to be dead, ha...   \n",
       "2     A cryptic message from Bond’s past sends him o...   \n",
       "3     Following the death of District Attorney Harve...   \n",
       "4     John Carter is a war-weary, former military ca...   \n",
       "...                                                 ...   \n",
       "4804  El Mariachi just wants to play his guitar and ...   \n",
       "4805  A newlywed couple's honeymoon is upended by th...   \n",
       "4806  \"Signed, Sealed, Delivered\" introduces a dedic...   \n",
       "4807  When ambitious New York attorney Sam is sent t...   \n",
       "4808  Ever since the second grade when he first saw ...   \n",
       "\n",
       "                                            description  \\\n",
       "0     In the 22nd century, a paraplegic Marine is di...   \n",
       "1     Captain Barbossa, long believed to be dead, ha...   \n",
       "2     A cryptic message from Bond’s past sends him o...   \n",
       "3     Following the death of District Attorney Harve...   \n",
       "4     John Carter is a war-weary, former military ca...   \n",
       "...                                                 ...   \n",
       "4804  El Mariachi just wants to play his guitar and ...   \n",
       "4805  A newlywed couple's honeymoon is upended by th...   \n",
       "4806  \"Signed, Sealed, Delivered\" introduces a dedic...   \n",
       "4807  When ambitious New York attorney Sam is sent t...   \n",
       "4808  Ever since the second grade when he first saw ...   \n",
       "\n",
       "                                   tags_clean  \n",
       "0     Action Adventure Fantasy Sciencefiction  \n",
       "1                    Action Adventure Fantasy  \n",
       "2                                     M While  \n",
       "3                 Action Crime Drama Thriller  \n",
       "4             Action Adventure Sciencefiction  \n",
       "...                                       ...  \n",
       "4804                    Action Crime Thriller  \n",
       "4805                           Comedy Romance  \n",
       "4806                     Comedy Drama Romance  \n",
       "4807                        Anonymous Written  \n",
       "4808                              Documentary  \n",
       "\n",
       "[4806 rows x 5 columns]"
      ]
     },
     "execution_count": 256,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "movies"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 257,
   "metadata": {},
   "outputs": [],
   "source": [
    "from collections import Counter\n",
    "import numpy as np\n",
    "\n",
    "count_genre = pd.Series([t_ for t in movies[\"tags_clean\"].to_list() for t_ in t.split(\" \")]).value_counts().to_frame()\n",
    "list_genres = list(count_genre.loc[count_genre[\"count\"]>75].index)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 258,
   "metadata": {},
   "outputs": [],
   "source": [
    "# index of movies with wrong tags\n",
    "list_index = []\n",
    "for index, t in enumerate(movies[\"tags_clean\"].to_list()):\n",
    "    for elem in t.split():\n",
    "        if elem not in list_genres:\n",
    "            list_index.append(index)\n",
    "            break"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 259,
   "metadata": {},
   "outputs": [],
   "source": [
    "dict_tags = dict()\n",
    "for index, description in zip(list_index, movies.iloc[list_index][\"tags\"].to_list()):\n",
    "    list_tags = []    \n",
    "    for genre in list_genres:\n",
    "        if genre in description: \n",
    "            list_tags.append(genre)\n",
    "        dict_tags[index] = \" \".join(list_tags)\n",
    "            "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 260,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "C:\\Users\\LaurèneDAVID\\AppData\\Local\\Temp\\ipykernel_9060\\521199459.py:1: SettingWithCopyWarning: \n",
      "A value is trying to be set on a copy of a slice from a DataFrame\n",
      "\n",
      "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
      "  movies[\"tags_clean\"].iloc[list_index] = list(dict_tags.values())\n"
     ]
    }
   ],
   "source": [
    "movies[\"tags_clean\"].iloc[list_index] = list(dict_tags.values())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 261,
   "metadata": {},
   "outputs": [],
   "source": [
    "movies.drop(columns=\"tags\",inplace=True)\n",
    "movies.rename({\"tags_clean\":\"genre\"},axis=1,inplace=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 262,
   "metadata": {},
   "outputs": [],
   "source": [
    "movies[\"genre\"] = movies[\"genre\"].apply(lambda x:x.replace(\" \",\", \").replace(\"Sciencefiction\", \"Science Fiction\").replace(\"\",\" \"))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 263,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>movie_id</th>\n",
       "      <th>title</th>\n",
       "      <th>description</th>\n",
       "      <th>genre</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>99861</td>\n",
       "      <td>Avengers: Age of Ultron</td>\n",
       "      <td>When Tony Stark tries to jumpstart a dormant p...</td>\n",
       "      <td>Action, Adventure, Science Fiction</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   movie_id                    title  \\\n",
       "7     99861  Avengers: Age of Ultron   \n",
       "\n",
       "                                         description  \\\n",
       "7  When Tony Stark tries to jumpstart a dormant p...   \n",
       "\n",
       "                                genre  \n",
       "7  Action, Adventure, Science Fiction  "
      ]
     },
     "execution_count": 263,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "movies.loc[movies[\"title\"]==\"Avengers: Age of Ultron\"]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 264,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'When Tony Stark tries to jumpstart a dormant peacekeeping program, things go awry and Earth’s Mightiest Heroes are put to the ultimate test as the fate of the planet hangs in the balance. As the villainous Ultron emerges, it is up to The Avengers to stop him from enacting his terrible plans, and soon uneasy alliances and unexpected action pave the way for an epic and unique global adventure. Action Adventure ScienceFiction marvelcomic sequel superhero basedoncomicbook vision superheroteam duringcreditsstinger marvelcinematicuniverse 3d RobertDowneyJr.'"
      ]
     },
     "execution_count": 264,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "movies[\"description\"].to_list()[7]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 265,
   "metadata": {},
   "outputs": [],
   "source": [
    "def clean_description_v2(text):\n",
    "    new_text = text.split(\". \")[-1]\n",
    "    for genre in list_genres:\n",
    "        if genre in new_text:\n",
    "            return \". \".join(text.split(\". \")[:-1] + [\"\"]).strip()\n",
    "    return text"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 266,
   "metadata": {},
   "outputs": [],
   "source": [
    "movies[\"description\"] = movies[\"description\"].apply(clean_description_v2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 267,
   "metadata": {},
   "outputs": [],
   "source": [
    "movies.to_pickle(\"data/movies/movies_dict2.pkl\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 268,
   "metadata": {},
   "outputs": [],
   "source": [
    "vote_info = pickle.load(open(os.path.join(path_data,\"vote_info.pkl\"),\"rb\"))\n",
    "vote = pd.DataFrame(vote_info)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 271,
   "metadata": {},
   "outputs": [],
   "source": [
    "movies.rename({\"movie_id\":\"id\"}, axis=1, inplace=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 272,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>id</th>\n",
       "      <th>title</th>\n",
       "      <th>description</th>\n",
       "      <th>genre</th>\n",
       "      <th>vote_average</th>\n",
       "      <th>vote_count</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>19995</td>\n",
       "      <td>Avatar</td>\n",
       "      <td>In the 22nd century, a paraplegic Marine is di...</td>\n",
       "      <td>Action, Adventure, Fantasy, Science Fiction</td>\n",
       "      <td>7.2</td>\n",
       "      <td>11800</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>285</td>\n",
       "      <td>Pirates of the Caribbean: At World's End</td>\n",
       "      <td>Captain Barbossa, long believed to be dead, ha...</td>\n",
       "      <td>Action, Adventure, Fantasy</td>\n",
       "      <td>6.9</td>\n",
       "      <td>4500</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>206647</td>\n",
       "      <td>Spectre</td>\n",
       "      <td>A cryptic message from Bond’s past sends him o...</td>\n",
       "      <td>Action, Adventure, Crime</td>\n",
       "      <td>6.3</td>\n",
       "      <td>4466</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>49026</td>\n",
       "      <td>The Dark Knight Rises</td>\n",
       "      <td>Following the death of District Attorney Harve...</td>\n",
       "      <td>Action, Crime, Drama, Thriller</td>\n",
       "      <td>7.6</td>\n",
       "      <td>9106</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>49529</td>\n",
       "      <td>John Carter</td>\n",
       "      <td>John Carter is a war-weary, former military ca...</td>\n",
       "      <td>Action, Adventure, Science Fiction</td>\n",
       "      <td>6.1</td>\n",
       "      <td>2124</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4801</th>\n",
       "      <td>9367</td>\n",
       "      <td>El Mariachi</td>\n",
       "      <td>El Mariachi just wants to play his guitar and ...</td>\n",
       "      <td>Action, Crime, Thriller</td>\n",
       "      <td>6.6</td>\n",
       "      <td>238</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4802</th>\n",
       "      <td>72766</td>\n",
       "      <td>Newlyweds</td>\n",
       "      <td>A newlywed couple's honeymoon is upended by th...</td>\n",
       "      <td>Comedy, Romance</td>\n",
       "      <td>5.9</td>\n",
       "      <td>5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4803</th>\n",
       "      <td>231617</td>\n",
       "      <td>Signed, Sealed, Delivered</td>\n",
       "      <td>\"Signed, Sealed, Delivered\" introduces a dedic...</td>\n",
       "      <td>Comedy, Drama, Romance</td>\n",
       "      <td>7.0</td>\n",
       "      <td>6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4804</th>\n",
       "      <td>126186</td>\n",
       "      <td>Shanghai Calling</td>\n",
       "      <td>When ambitious New York attorney Sam is sent t...</td>\n",
       "      <td></td>\n",
       "      <td>5.7</td>\n",
       "      <td>7</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4805</th>\n",
       "      <td>25975</td>\n",
       "      <td>My Date with Drew</td>\n",
       "      <td>Ever since the second grade when he first saw ...</td>\n",
       "      <td>Documentary</td>\n",
       "      <td>6.3</td>\n",
       "      <td>16</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>4806 rows × 6 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "          id                                     title  \\\n",
       "0      19995                                    Avatar   \n",
       "1        285  Pirates of the Caribbean: At World's End   \n",
       "2     206647                                   Spectre   \n",
       "3      49026                     The Dark Knight Rises   \n",
       "4      49529                               John Carter   \n",
       "...      ...                                       ...   \n",
       "4801    9367                               El Mariachi   \n",
       "4802   72766                                 Newlyweds   \n",
       "4803  231617                 Signed, Sealed, Delivered   \n",
       "4804  126186                          Shanghai Calling   \n",
       "4805   25975                         My Date with Drew   \n",
       "\n",
       "                                            description  \\\n",
       "0     In the 22nd century, a paraplegic Marine is di...   \n",
       "1     Captain Barbossa, long believed to be dead, ha...   \n",
       "2     A cryptic message from Bond’s past sends him o...   \n",
       "3     Following the death of District Attorney Harve...   \n",
       "4     John Carter is a war-weary, former military ca...   \n",
       "...                                                 ...   \n",
       "4801  El Mariachi just wants to play his guitar and ...   \n",
       "4802  A newlywed couple's honeymoon is upended by th...   \n",
       "4803  \"Signed, Sealed, Delivered\" introduces a dedic...   \n",
       "4804  When ambitious New York attorney Sam is sent t...   \n",
       "4805  Ever since the second grade when he first saw ...   \n",
       "\n",
       "                                            genre  vote_average  vote_count  \n",
       "0     Action, Adventure, Fantasy, Science Fiction           7.2       11800  \n",
       "1                      Action, Adventure, Fantasy           6.9        4500  \n",
       "2                        Action, Adventure, Crime           6.3        4466  \n",
       "3                  Action, Crime, Drama, Thriller           7.6        9106  \n",
       "4              Action, Adventure, Science Fiction           6.1        2124  \n",
       "...                                           ...           ...         ...  \n",
       "4801                      Action, Crime, Thriller           6.6         238  \n",
       "4802                              Comedy, Romance           5.9           5  \n",
       "4803                       Comedy, Drama, Romance           7.0           6  \n",
       "4804                                                        5.7           7  \n",
       "4805                                  Documentary           6.3          16  \n",
       "\n",
       "[4806 rows x 6 columns]"
      ]
     },
     "execution_count": 272,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "movies.merge(vote, on=\"id\", how=\"left\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "venv",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}