暫無描述

Simple Recommender.ipynb 24KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698
  1. {
  2. "cells": [
  3. {
  4. "cell_type": "code",
  5. "execution_count": 1,
  6. "metadata": {},
  7. "outputs": [
  8. {
  9. "name": "stderr",
  10. "output_type": "stream",
  11. "text": [
  12. "/var/folders/dv/107570dd01b_m3wvmvv0g9lm0000gn/T/ipykernel_18673/1882081200.py:4: DtypeWarning: Columns (10) have mixed types. Specify dtype option on import or set low_memory=False.\n",
  13. " df = pd.read_csv('../data/movies_metadata.csv')\n"
  14. ]
  15. },
  16. {
  17. "data": {
  18. "text/html": [
  19. "<div>\n",
  20. "<style scoped>\n",
  21. " .dataframe tbody tr th:only-of-type {\n",
  22. " vertical-align: middle;\n",
  23. " }\n",
  24. "\n",
  25. " .dataframe tbody tr th {\n",
  26. " vertical-align: top;\n",
  27. " }\n",
  28. "\n",
  29. " .dataframe thead th {\n",
  30. " text-align: right;\n",
  31. " }\n",
  32. "</style>\n",
  33. "<table border=\"1\" class=\"dataframe\">\n",
  34. " <thead>\n",
  35. " <tr style=\"text-align: right;\">\n",
  36. " <th></th>\n",
  37. " <th>adult</th>\n",
  38. " <th>belongs_to_collection</th>\n",
  39. " <th>budget</th>\n",
  40. " <th>genres</th>\n",
  41. " <th>homepage</th>\n",
  42. " <th>id</th>\n",
  43. " <th>imdb_id</th>\n",
  44. " <th>original_language</th>\n",
  45. " <th>original_title</th>\n",
  46. " <th>overview</th>\n",
  47. " <th>...</th>\n",
  48. " <th>release_date</th>\n",
  49. " <th>revenue</th>\n",
  50. " <th>runtime</th>\n",
  51. " <th>spoken_languages</th>\n",
  52. " <th>status</th>\n",
  53. " <th>tagline</th>\n",
  54. " <th>title</th>\n",
  55. " <th>video</th>\n",
  56. " <th>vote_average</th>\n",
  57. " <th>vote_count</th>\n",
  58. " </tr>\n",
  59. " </thead>\n",
  60. " <tbody>\n",
  61. " <tr>\n",
  62. " <th>0</th>\n",
  63. " <td>False</td>\n",
  64. " <td>{'id': 10194, 'name': 'Toy Story Collection', ...</td>\n",
  65. " <td>30000000</td>\n",
  66. " <td>[{'id': 16, 'name': 'Animation'}, {'id': 35, '...</td>\n",
  67. " <td>http://toystory.disney.com/toy-story</td>\n",
  68. " <td>862</td>\n",
  69. " <td>tt0114709</td>\n",
  70. " <td>en</td>\n",
  71. " <td>Toy Story</td>\n",
  72. " <td>Led by Woody, Andy's toys live happily in his ...</td>\n",
  73. " <td>...</td>\n",
  74. " <td>1995-10-30</td>\n",
  75. " <td>373554033.0</td>\n",
  76. " <td>81.0</td>\n",
  77. " <td>[{'iso_639_1': 'en', 'name': 'English'}]</td>\n",
  78. " <td>Released</td>\n",
  79. " <td>NaN</td>\n",
  80. " <td>Toy Story</td>\n",
  81. " <td>False</td>\n",
  82. " <td>7.7</td>\n",
  83. " <td>5415.0</td>\n",
  84. " </tr>\n",
  85. " <tr>\n",
  86. " <th>1</th>\n",
  87. " <td>False</td>\n",
  88. " <td>NaN</td>\n",
  89. " <td>65000000</td>\n",
  90. " <td>[{'id': 12, 'name': 'Adventure'}, {'id': 14, '...</td>\n",
  91. " <td>NaN</td>\n",
  92. " <td>8844</td>\n",
  93. " <td>tt0113497</td>\n",
  94. " <td>en</td>\n",
  95. " <td>Jumanji</td>\n",
  96. " <td>When siblings Judy and Peter discover an encha...</td>\n",
  97. " <td>...</td>\n",
  98. " <td>1995-12-15</td>\n",
  99. " <td>262797249.0</td>\n",
  100. " <td>104.0</td>\n",
  101. " <td>[{'iso_639_1': 'en', 'name': 'English'}, {'iso...</td>\n",
  102. " <td>Released</td>\n",
  103. " <td>Roll the dice and unleash the excitement!</td>\n",
  104. " <td>Jumanji</td>\n",
  105. " <td>False</td>\n",
  106. " <td>6.9</td>\n",
  107. " <td>2413.0</td>\n",
  108. " </tr>\n",
  109. " <tr>\n",
  110. " <th>2</th>\n",
  111. " <td>False</td>\n",
  112. " <td>{'id': 119050, 'name': 'Grumpy Old Men Collect...</td>\n",
  113. " <td>0</td>\n",
  114. " <td>[{'id': 10749, 'name': 'Romance'}, {'id': 35, ...</td>\n",
  115. " <td>NaN</td>\n",
  116. " <td>15602</td>\n",
  117. " <td>tt0113228</td>\n",
  118. " <td>en</td>\n",
  119. " <td>Grumpier Old Men</td>\n",
  120. " <td>A family wedding reignites the ancient feud be...</td>\n",
  121. " <td>...</td>\n",
  122. " <td>1995-12-22</td>\n",
  123. " <td>0.0</td>\n",
  124. " <td>101.0</td>\n",
  125. " <td>[{'iso_639_1': 'en', 'name': 'English'}]</td>\n",
  126. " <td>Released</td>\n",
  127. " <td>Still Yelling. Still Fighting. Still Ready for...</td>\n",
  128. " <td>Grumpier Old Men</td>\n",
  129. " <td>False</td>\n",
  130. " <td>6.5</td>\n",
  131. " <td>92.0</td>\n",
  132. " </tr>\n",
  133. " <tr>\n",
  134. " <th>3</th>\n",
  135. " <td>False</td>\n",
  136. " <td>NaN</td>\n",
  137. " <td>16000000</td>\n",
  138. " <td>[{'id': 35, 'name': 'Comedy'}, {'id': 18, 'nam...</td>\n",
  139. " <td>NaN</td>\n",
  140. " <td>31357</td>\n",
  141. " <td>tt0114885</td>\n",
  142. " <td>en</td>\n",
  143. " <td>Waiting to Exhale</td>\n",
  144. " <td>Cheated on, mistreated and stepped on, the wom...</td>\n",
  145. " <td>...</td>\n",
  146. " <td>1995-12-22</td>\n",
  147. " <td>81452156.0</td>\n",
  148. " <td>127.0</td>\n",
  149. " <td>[{'iso_639_1': 'en', 'name': 'English'}]</td>\n",
  150. " <td>Released</td>\n",
  151. " <td>Friends are the people who let you be yourself...</td>\n",
  152. " <td>Waiting to Exhale</td>\n",
  153. " <td>False</td>\n",
  154. " <td>6.1</td>\n",
  155. " <td>34.0</td>\n",
  156. " </tr>\n",
  157. " <tr>\n",
  158. " <th>4</th>\n",
  159. " <td>False</td>\n",
  160. " <td>{'id': 96871, 'name': 'Father of the Bride Col...</td>\n",
  161. " <td>0</td>\n",
  162. " <td>[{'id': 35, 'name': 'Comedy'}]</td>\n",
  163. " <td>NaN</td>\n",
  164. " <td>11862</td>\n",
  165. " <td>tt0113041</td>\n",
  166. " <td>en</td>\n",
  167. " <td>Father of the Bride Part II</td>\n",
  168. " <td>Just when George Banks has recovered from his ...</td>\n",
  169. " <td>...</td>\n",
  170. " <td>1995-02-10</td>\n",
  171. " <td>76578911.0</td>\n",
  172. " <td>106.0</td>\n",
  173. " <td>[{'iso_639_1': 'en', 'name': 'English'}]</td>\n",
  174. " <td>Released</td>\n",
  175. " <td>Just When His World Is Back To Normal... He's ...</td>\n",
  176. " <td>Father of the Bride Part II</td>\n",
  177. " <td>False</td>\n",
  178. " <td>5.7</td>\n",
  179. " <td>173.0</td>\n",
  180. " </tr>\n",
  181. " </tbody>\n",
  182. "</table>\n",
  183. "<p>5 rows × 24 columns</p>\n",
  184. "</div>"
  185. ],
  186. "text/plain": [
  187. " adult belongs_to_collection budget \\\n",
  188. "0 False {'id': 10194, 'name': 'Toy Story Collection', ... 30000000 \n",
  189. "1 False NaN 65000000 \n",
  190. "2 False {'id': 119050, 'name': 'Grumpy Old Men Collect... 0 \n",
  191. "3 False NaN 16000000 \n",
  192. "4 False {'id': 96871, 'name': 'Father of the Bride Col... 0 \n",
  193. "\n",
  194. " genres \\\n",
  195. "0 [{'id': 16, 'name': 'Animation'}, {'id': 35, '... \n",
  196. "1 [{'id': 12, 'name': 'Adventure'}, {'id': 14, '... \n",
  197. "2 [{'id': 10749, 'name': 'Romance'}, {'id': 35, ... \n",
  198. "3 [{'id': 35, 'name': 'Comedy'}, {'id': 18, 'nam... \n",
  199. "4 [{'id': 35, 'name': 'Comedy'}] \n",
  200. "\n",
  201. " homepage id imdb_id original_language \\\n",
  202. "0 http://toystory.disney.com/toy-story 862 tt0114709 en \n",
  203. "1 NaN 8844 tt0113497 en \n",
  204. "2 NaN 15602 tt0113228 en \n",
  205. "3 NaN 31357 tt0114885 en \n",
  206. "4 NaN 11862 tt0113041 en \n",
  207. "\n",
  208. " original_title \\\n",
  209. "0 Toy Story \n",
  210. "1 Jumanji \n",
  211. "2 Grumpier Old Men \n",
  212. "3 Waiting to Exhale \n",
  213. "4 Father of the Bride Part II \n",
  214. "\n",
  215. " overview ... release_date \\\n",
  216. "0 Led by Woody, Andy's toys live happily in his ... ... 1995-10-30 \n",
  217. "1 When siblings Judy and Peter discover an encha... ... 1995-12-15 \n",
  218. "2 A family wedding reignites the ancient feud be... ... 1995-12-22 \n",
  219. "3 Cheated on, mistreated and stepped on, the wom... ... 1995-12-22 \n",
  220. "4 Just when George Banks has recovered from his ... ... 1995-02-10 \n",
  221. "\n",
  222. " revenue runtime spoken_languages \\\n",
  223. "0 373554033.0 81.0 [{'iso_639_1': 'en', 'name': 'English'}] \n",
  224. "1 262797249.0 104.0 [{'iso_639_1': 'en', 'name': 'English'}, {'iso... \n",
  225. "2 0.0 101.0 [{'iso_639_1': 'en', 'name': 'English'}] \n",
  226. "3 81452156.0 127.0 [{'iso_639_1': 'en', 'name': 'English'}] \n",
  227. "4 76578911.0 106.0 [{'iso_639_1': 'en', 'name': 'English'}] \n",
  228. "\n",
  229. " status tagline \\\n",
  230. "0 Released NaN \n",
  231. "1 Released Roll the dice and unleash the excitement! \n",
  232. "2 Released Still Yelling. Still Fighting. Still Ready for... \n",
  233. "3 Released Friends are the people who let you be yourself... \n",
  234. "4 Released Just When His World Is Back To Normal... He's ... \n",
  235. "\n",
  236. " title video vote_average vote_count \n",
  237. "0 Toy Story False 7.7 5415.0 \n",
  238. "1 Jumanji False 6.9 2413.0 \n",
  239. "2 Grumpier Old Men False 6.5 92.0 \n",
  240. "3 Waiting to Exhale False 6.1 34.0 \n",
  241. "4 Father of the Bride Part II False 5.7 173.0 \n",
  242. "\n",
  243. "[5 rows x 24 columns]"
  244. ]
  245. },
  246. "execution_count": 1,
  247. "metadata": {},
  248. "output_type": "execute_result"
  249. }
  250. ],
  251. "source": [
  252. "import pandas as pd\n",
  253. "import numpy as np\n",
  254. "\n",
  255. "df = pd.read_csv('../data/movies_metadata.csv')\n",
  256. "df.head()"
  257. ]
  258. },
  259. {
  260. "cell_type": "code",
  261. "execution_count": 2,
  262. "metadata": {},
  263. "outputs": [
  264. {
  265. "data": {
  266. "text/plain": [
  267. "50.0"
  268. ]
  269. },
  270. "execution_count": 2,
  271. "metadata": {},
  272. "output_type": "execute_result"
  273. }
  274. ],
  275. "source": [
  276. "#Calculate the number of votes garnered by the 80th percentile movie\n",
  277. "m = df['vote_count'].quantile(0.80)\n",
  278. "m"
  279. ]
  280. },
  281. {
  282. "cell_type": "code",
  283. "execution_count": 3,
  284. "metadata": {},
  285. "outputs": [
  286. {
  287. "data": {
  288. "text/plain": [
  289. "(8963, 24)"
  290. ]
  291. },
  292. "execution_count": 3,
  293. "metadata": {},
  294. "output_type": "execute_result"
  295. }
  296. ],
  297. "source": [
  298. "#Only consider movies longer than 45 minutes and shorter than 300 minutes\n",
  299. "q_movies = df[(df['runtime'] >= 45) & (df['runtime'] <= 300)]\n",
  300. "\n",
  301. "#Only consider movies that have garnered more than m votes\n",
  302. "q_movies = q_movies[q_movies['vote_count'] >= m]\n",
  303. "\n",
  304. "#Inspect the number of movies that made the cut\n",
  305. "q_movies.shape"
  306. ]
  307. },
  308. {
  309. "cell_type": "code",
  310. "execution_count": 4,
  311. "metadata": {},
  312. "outputs": [
  313. {
  314. "data": {
  315. "text/plain": [
  316. "5.618207215134185"
  317. ]
  318. },
  319. "execution_count": 4,
  320. "metadata": {},
  321. "output_type": "execute_result"
  322. }
  323. ],
  324. "source": [
  325. "# Calculate C\n",
  326. "C = df['vote_average'].mean()\n",
  327. "C"
  328. ]
  329. },
  330. {
  331. "cell_type": "code",
  332. "execution_count": 5,
  333. "metadata": {},
  334. "outputs": [],
  335. "source": [
  336. "# Function to compute the IMDB weighted rating for each movie\n",
  337. "def weighted_rating(x, m=m, C=C):\n",
  338. " v = x['vote_count']\n",
  339. " R = x['vote_average']\n",
  340. " # Compute the weighted score\n",
  341. " return (v/(v+m) * R) + (m/(m+v) * C)"
  342. ]
  343. },
  344. {
  345. "cell_type": "code",
  346. "execution_count": 6,
  347. "metadata": {},
  348. "outputs": [],
  349. "source": [
  350. "# Compute the score using the weighted_rating function defined above\n",
  351. "q_movies['score'] = q_movies.apply(weighted_rating, axis=1)"
  352. ]
  353. },
  354. {
  355. "cell_type": "code",
  356. "execution_count": 7,
  357. "metadata": {},
  358. "outputs": [
  359. {
  360. "data": {
  361. "text/html": [
  362. "<div>\n",
  363. "<style scoped>\n",
  364. " .dataframe tbody tr th:only-of-type {\n",
  365. " vertical-align: middle;\n",
  366. " }\n",
  367. "\n",
  368. " .dataframe tbody tr th {\n",
  369. " vertical-align: top;\n",
  370. " }\n",
  371. "\n",
  372. " .dataframe thead th {\n",
  373. " text-align: right;\n",
  374. " }\n",
  375. "</style>\n",
  376. "<table border=\"1\" class=\"dataframe\">\n",
  377. " <thead>\n",
  378. " <tr style=\"text-align: right;\">\n",
  379. " <th></th>\n",
  380. " <th>title</th>\n",
  381. " <th>vote_count</th>\n",
  382. " <th>vote_average</th>\n",
  383. " <th>score</th>\n",
  384. " <th>runtime</th>\n",
  385. " </tr>\n",
  386. " </thead>\n",
  387. " <tbody>\n",
  388. " <tr>\n",
  389. " <th>10309</th>\n",
  390. " <td>Dilwale Dulhania Le Jayenge</td>\n",
  391. " <td>661.0</td>\n",
  392. " <td>9.1</td>\n",
  393. " <td>8.855148</td>\n",
  394. " <td>190.0</td>\n",
  395. " </tr>\n",
  396. " <tr>\n",
  397. " <th>314</th>\n",
  398. " <td>The Shawshank Redemption</td>\n",
  399. " <td>8358.0</td>\n",
  400. " <td>8.5</td>\n",
  401. " <td>8.482863</td>\n",
  402. " <td>142.0</td>\n",
  403. " </tr>\n",
  404. " <tr>\n",
  405. " <th>834</th>\n",
  406. " <td>The Godfather</td>\n",
  407. " <td>6024.0</td>\n",
  408. " <td>8.5</td>\n",
  409. " <td>8.476278</td>\n",
  410. " <td>175.0</td>\n",
  411. " </tr>\n",
  412. " <tr>\n",
  413. " <th>40251</th>\n",
  414. " <td>Your Name.</td>\n",
  415. " <td>1030.0</td>\n",
  416. " <td>8.5</td>\n",
  417. " <td>8.366584</td>\n",
  418. " <td>106.0</td>\n",
  419. " </tr>\n",
  420. " <tr>\n",
  421. " <th>12481</th>\n",
  422. " <td>The Dark Knight</td>\n",
  423. " <td>12269.0</td>\n",
  424. " <td>8.3</td>\n",
  425. " <td>8.289115</td>\n",
  426. " <td>152.0</td>\n",
  427. " </tr>\n",
  428. " <tr>\n",
  429. " <th>2843</th>\n",
  430. " <td>Fight Club</td>\n",
  431. " <td>9678.0</td>\n",
  432. " <td>8.3</td>\n",
  433. " <td>8.286216</td>\n",
  434. " <td>139.0</td>\n",
  435. " </tr>\n",
  436. " <tr>\n",
  437. " <th>292</th>\n",
  438. " <td>Pulp Fiction</td>\n",
  439. " <td>8670.0</td>\n",
  440. " <td>8.3</td>\n",
  441. " <td>8.284623</td>\n",
  442. " <td>154.0</td>\n",
  443. " </tr>\n",
  444. " <tr>\n",
  445. " <th>522</th>\n",
  446. " <td>Schindler's List</td>\n",
  447. " <td>4436.0</td>\n",
  448. " <td>8.3</td>\n",
  449. " <td>8.270109</td>\n",
  450. " <td>195.0</td>\n",
  451. " </tr>\n",
  452. " <tr>\n",
  453. " <th>23673</th>\n",
  454. " <td>Whiplash</td>\n",
  455. " <td>4376.0</td>\n",
  456. " <td>8.3</td>\n",
  457. " <td>8.269704</td>\n",
  458. " <td>105.0</td>\n",
  459. " </tr>\n",
  460. " <tr>\n",
  461. " <th>5481</th>\n",
  462. " <td>Spirited Away</td>\n",
  463. " <td>3968.0</td>\n",
  464. " <td>8.3</td>\n",
  465. " <td>8.266628</td>\n",
  466. " <td>125.0</td>\n",
  467. " </tr>\n",
  468. " <tr>\n",
  469. " <th>2211</th>\n",
  470. " <td>Life Is Beautiful</td>\n",
  471. " <td>3643.0</td>\n",
  472. " <td>8.3</td>\n",
  473. " <td>8.263691</td>\n",
  474. " <td>116.0</td>\n",
  475. " </tr>\n",
  476. " <tr>\n",
  477. " <th>1178</th>\n",
  478. " <td>The Godfather: Part II</td>\n",
  479. " <td>3418.0</td>\n",
  480. " <td>8.3</td>\n",
  481. " <td>8.261335</td>\n",
  482. " <td>200.0</td>\n",
  483. " </tr>\n",
  484. " <tr>\n",
  485. " <th>1152</th>\n",
  486. " <td>One Flew Over the Cuckoo's Nest</td>\n",
  487. " <td>3001.0</td>\n",
  488. " <td>8.3</td>\n",
  489. " <td>8.256051</td>\n",
  490. " <td>133.0</td>\n",
  491. " </tr>\n",
  492. " <tr>\n",
  493. " <th>1176</th>\n",
  494. " <td>Psycho</td>\n",
  495. " <td>2405.0</td>\n",
  496. " <td>8.3</td>\n",
  497. " <td>8.245381</td>\n",
  498. " <td>109.0</td>\n",
  499. " </tr>\n",
  500. " <tr>\n",
  501. " <th>351</th>\n",
  502. " <td>Forrest Gump</td>\n",
  503. " <td>8147.0</td>\n",
  504. " <td>8.2</td>\n",
  505. " <td>8.184252</td>\n",
  506. " <td>142.0</td>\n",
  507. " </tr>\n",
  508. " <tr>\n",
  509. " <th>1184</th>\n",
  510. " <td>Once Upon a Time in America</td>\n",
  511. " <td>1104.0</td>\n",
  512. " <td>8.3</td>\n",
  513. " <td>8.183804</td>\n",
  514. " <td>229.0</td>\n",
  515. " </tr>\n",
  516. " <tr>\n",
  517. " <th>1154</th>\n",
  518. " <td>The Empire Strikes Back</td>\n",
  519. " <td>5998.0</td>\n",
  520. " <td>8.2</td>\n",
  521. " <td>8.178656</td>\n",
  522. " <td>124.0</td>\n",
  523. " </tr>\n",
  524. " <tr>\n",
  525. " <th>18465</th>\n",
  526. " <td>The Intouchables</td>\n",
  527. " <td>5410.0</td>\n",
  528. " <td>8.2</td>\n",
  529. " <td>8.176357</td>\n",
  530. " <td>112.0</td>\n",
  531. " </tr>\n",
  532. " <tr>\n",
  533. " <th>289</th>\n",
  534. " <td>Leon: The Professional</td>\n",
  535. " <td>4293.0</td>\n",
  536. " <td>8.2</td>\n",
  537. " <td>8.170276</td>\n",
  538. " <td>110.0</td>\n",
  539. " </tr>\n",
  540. " <tr>\n",
  541. " <th>3030</th>\n",
  542. " <td>The Green Mile</td>\n",
  543. " <td>4166.0</td>\n",
  544. " <td>8.2</td>\n",
  545. " <td>8.169381</td>\n",
  546. " <td>189.0</td>\n",
  547. " </tr>\n",
  548. " <tr>\n",
  549. " <th>1170</th>\n",
  550. " <td>GoodFellas</td>\n",
  551. " <td>3211.0</td>\n",
  552. " <td>8.2</td>\n",
  553. " <td>8.160414</td>\n",
  554. " <td>145.0</td>\n",
  555. " </tr>\n",
  556. " <tr>\n",
  557. " <th>2216</th>\n",
  558. " <td>American History X</td>\n",
  559. " <td>3120.0</td>\n",
  560. " <td>8.2</td>\n",
  561. " <td>8.159278</td>\n",
  562. " <td>119.0</td>\n",
  563. " </tr>\n",
  564. " <tr>\n",
  565. " <th>1161</th>\n",
  566. " <td>12 Angry Men</td>\n",
  567. " <td>2130.0</td>\n",
  568. " <td>8.2</td>\n",
  569. " <td>8.140785</td>\n",
  570. " <td>96.0</td>\n",
  571. " </tr>\n",
  572. " <tr>\n",
  573. " <th>9698</th>\n",
  574. " <td>Howl's Moving Castle</td>\n",
  575. " <td>2049.0</td>\n",
  576. " <td>8.2</td>\n",
  577. " <td>8.138499</td>\n",
  578. " <td>119.0</td>\n",
  579. " </tr>\n",
  580. " <tr>\n",
  581. " <th>2884</th>\n",
  582. " <td>Princess Mononoke</td>\n",
  583. " <td>2041.0</td>\n",
  584. " <td>8.2</td>\n",
  585. " <td>8.138264</td>\n",
  586. " <td>134.0</td>\n",
  587. " </tr>\n",
  588. " </tbody>\n",
  589. "</table>\n",
  590. "</div>"
  591. ],
  592. "text/plain": [
  593. " title vote_count vote_average score \\\n",
  594. "10309 Dilwale Dulhania Le Jayenge 661.0 9.1 8.855148 \n",
  595. "314 The Shawshank Redemption 8358.0 8.5 8.482863 \n",
  596. "834 The Godfather 6024.0 8.5 8.476278 \n",
  597. "40251 Your Name. 1030.0 8.5 8.366584 \n",
  598. "12481 The Dark Knight 12269.0 8.3 8.289115 \n",
  599. "2843 Fight Club 9678.0 8.3 8.286216 \n",
  600. "292 Pulp Fiction 8670.0 8.3 8.284623 \n",
  601. "522 Schindler's List 4436.0 8.3 8.270109 \n",
  602. "23673 Whiplash 4376.0 8.3 8.269704 \n",
  603. "5481 Spirited Away 3968.0 8.3 8.266628 \n",
  604. "2211 Life Is Beautiful 3643.0 8.3 8.263691 \n",
  605. "1178 The Godfather: Part II 3418.0 8.3 8.261335 \n",
  606. "1152 One Flew Over the Cuckoo's Nest 3001.0 8.3 8.256051 \n",
  607. "1176 Psycho 2405.0 8.3 8.245381 \n",
  608. "351 Forrest Gump 8147.0 8.2 8.184252 \n",
  609. "1184 Once Upon a Time in America 1104.0 8.3 8.183804 \n",
  610. "1154 The Empire Strikes Back 5998.0 8.2 8.178656 \n",
  611. "18465 The Intouchables 5410.0 8.2 8.176357 \n",
  612. "289 Leon: The Professional 4293.0 8.2 8.170276 \n",
  613. "3030 The Green Mile 4166.0 8.2 8.169381 \n",
  614. "1170 GoodFellas 3211.0 8.2 8.160414 \n",
  615. "2216 American History X 3120.0 8.2 8.159278 \n",
  616. "1161 12 Angry Men 2130.0 8.2 8.140785 \n",
  617. "9698 Howl's Moving Castle 2049.0 8.2 8.138499 \n",
  618. "2884 Princess Mononoke 2041.0 8.2 8.138264 \n",
  619. "\n",
  620. " runtime \n",
  621. "10309 190.0 \n",
  622. "314 142.0 \n",
  623. "834 175.0 \n",
  624. "40251 106.0 \n",
  625. "12481 152.0 \n",
  626. "2843 139.0 \n",
  627. "292 154.0 \n",
  628. "522 195.0 \n",
  629. "23673 105.0 \n",
  630. "5481 125.0 \n",
  631. "2211 116.0 \n",
  632. "1178 200.0 \n",
  633. "1152 133.0 \n",
  634. "1176 109.0 \n",
  635. "351 142.0 \n",
  636. "1184 229.0 \n",
  637. "1154 124.0 \n",
  638. "18465 112.0 \n",
  639. "289 110.0 \n",
  640. "3030 189.0 \n",
  641. "1170 145.0 \n",
  642. "2216 119.0 \n",
  643. "1161 96.0 \n",
  644. "9698 119.0 \n",
  645. "2884 134.0 "
  646. ]
  647. },
  648. "execution_count": 7,
  649. "metadata": {},
  650. "output_type": "execute_result"
  651. }
  652. ],
  653. "source": [
  654. "#Sort movies in descending order of their scores\n",
  655. "q_movies = q_movies.sort_values('score', ascending=False)\n",
  656. "\n",
  657. "#Print the top 25 movies\n",
  658. "q_movies[['title', 'vote_count', 'vote_average', 'score', 'runtime']].head(25)"
  659. ]
  660. },
  661. {
  662. "cell_type": "code",
  663. "execution_count": null,
  664. "metadata": {},
  665. "outputs": [],
  666. "source": []
  667. },
  668. {
  669. "cell_type": "code",
  670. "execution_count": null,
  671. "metadata": {},
  672. "outputs": [],
  673. "source": []
  674. }
  675. ],
  676. "metadata": {
  677. "kernelspec": {
  678. "display_name": "Python 3 (ipykernel)",
  679. "language": "python",
  680. "name": "python3"
  681. },
  682. "language_info": {
  683. "codemirror_mode": {
  684. "name": "ipython",
  685. "version": 3
  686. },
  687. "file_extension": ".py",
  688. "mimetype": "text/x-python",
  689. "name": "python",
  690. "nbconvert_exporter": "python",
  691. "pygments_lexer": "ipython3",
  692. "version": "3.10.4"
  693. }
  694. },
  695. "nbformat": 4,
  696. "nbformat_minor": 2
  697. }