{ "cells": [ { "cell_type": "code", "execution_count": 1, "id": "df0e6352", "metadata": { "execution": { "iopub.execute_input": "2024-04-17T07:27:14.280674Z", "iopub.status.busy": "2024-04-17T07:27:14.280358Z", "iopub.status.idle": "2024-04-17T07:27:14.594102Z", "shell.execute_reply": "2024-04-17T07:27:14.593759Z" } }, "outputs": [], "source": [ "import pandas as pd\n", "\n", "from lets_plot import *" ] }, { "cell_type": "code", "execution_count": 2, "id": "3d325167", "metadata": { "execution": { "iopub.execute_input": "2024-04-17T07:27:14.595525Z", "iopub.status.busy": "2024-04-17T07:27:14.595417Z", "iopub.status.idle": "2024-04-17T07:27:14.597875Z", "shell.execute_reply": "2024-04-17T07:27:14.597701Z" } }, "outputs": [ { "data": { "text/html": [ "\n", "
\n", " \n", " " ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "LetsPlot.setup_html()" ] }, { "cell_type": "code", "execution_count": 3, "id": "2b33ff55", "metadata": { "execution": { "iopub.execute_input": "2024-04-17T07:27:14.598895Z", "iopub.status.busy": "2024-04-17T07:27:14.598820Z", "iopub.status.idle": "2024-04-17T07:27:15.447229Z", "shell.execute_reply": "2024-04-17T07:27:15.447021Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "(7338, 12)\n" ] }, { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
show_idtypetitledirectorcastcountrydate_addedrelease_yearratingdurationgenresdescription
0s1TV Show3%NaNJoão Miguel, Bianca Comparato, Michel Gomes, R...Brazil14-Aug-202020TV-MA4International TV Shows, TV Dramas, TV Sci-Fi &...In a future where the elite inhabit an island ...
1s10Movie1920Vikram BhattRajneesh Duggal, Adah Sharma, Indraneil Sengup...India15-Dec-172008TV-MA143Horror Movies, International Movies, ThrillersAn architect and his wife move into a castle t...
2s100Movie3 HeroinesIman BrotosenoReza Rahadian, Bunga Citra Lestari, Tara Basro...Indonesia05-Jan-192016TV-PG124Dramas, International Movies, Sports MoviesThree Indonesian women break records by becomi...
3s1000MovieBlue Mountain State: The Rise of ThadlandLev L. SpiroAlan Ritchson, Darin Brooks, James Cade, Rob R...United States01-Mar-162016R90ComediesNew NFL star Thad buys his old teammates' belo...
4s1001TV ShowBlue Planet IINaNDavid AttenboroughUnited Kingdom03-Dec-182017TV-G1British TV Shows, Docuseries, Science & Nature TVThis sequel to the award-winning nature series...
\n", "
" ], "text/plain": [ " show_id type title director \\\n", "0 s1 TV Show 3% NaN \n", "1 s10 Movie 1920 Vikram Bhatt \n", "2 s100 Movie 3 Heroines Iman Brotoseno \n", "3 s1000 Movie Blue Mountain State: The Rise of Thadland Lev L. Spiro \n", "4 s1001 TV Show Blue Planet II NaN \n", "\n", " cast country \\\n", "0 João Miguel, Bianca Comparato, Michel Gomes, R... Brazil \n", "1 Rajneesh Duggal, Adah Sharma, Indraneil Sengup... India \n", "2 Reza Rahadian, Bunga Citra Lestari, Tara Basro... Indonesia \n", "3 Alan Ritchson, Darin Brooks, James Cade, Rob R... United States \n", "4 David Attenborough United Kingdom \n", "\n", " date_added release_year rating duration \\\n", "0 14-Aug-20 2020 TV-MA 4 \n", "1 15-Dec-17 2008 TV-MA 143 \n", "2 05-Jan-19 2016 TV-PG 124 \n", "3 01-Mar-16 2016 R 90 \n", "4 03-Dec-18 2017 TV-G 1 \n", "\n", " genres \\\n", "0 International TV Shows, TV Dramas, TV Sci-Fi &... \n", "1 Horror Movies, International Movies, Thrillers \n", "2 Dramas, International Movies, Sports Movies \n", "3 Comedies \n", "4 British TV Shows, Docuseries, Science & Nature TV \n", "\n", " description \n", "0 In a future where the elite inhabit an island ... \n", "1 An architect and his wife move into a castle t... \n", "2 Three Indonesian women break records by becomi... \n", "3 New NFL star Thad buys his old teammates' belo... \n", "4 This sequel to the award-winning nature series... " ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df = pd.read_csv(\"https://raw.githubusercontent.com/JetBrains/lets-plot-docs/master/data/NetFlix.csv\")\n", "df = df[df[\"release_year\"] >= 2000]\n", "print(df.shape)\n", "df.head()" ] }, { "cell_type": "code", "execution_count": 4, "id": "64f9ce53", "metadata": { "execution": { "iopub.execute_input": "2024-04-17T07:27:15.448311Z", "iopub.status.busy": "2024-04-17T07:27:15.448226Z", "iopub.status.idle": "2024-04-17T07:27:15.890809Z", "shell.execute_reply": "2024-04-17T07:27:15.890567Z" } }, "outputs": [ { "data": { "text/html": [ "
\n", " " ], "text/plain": [ "" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "movies_df = df[(df[\"type\"] == \"Movie\")&(df[\"genres\"] != \"Movies\")]\n", "by_genre_df = pd.melt(\n", " movies_df[\"genres\"].str.split(\", \", expand=True).assign(duration=movies_df[\"duration\"]),\n", " id_vars=[\"duration\"], value_vars=[0, 1, 2], value_name=\"genre\"\n", ")[[\"genre\", \"duration\"]].dropna(subset=[\"genre\"])\n", "by_genre_df = by_genre_df.assign(\n", " duration_mean=by_genre_df.merge(by_genre_df.groupby(\"genre\")[\"duration\"].mean(), on=\"genre\", suffixes=[\"\", \"_mean\"])[\"duration_mean\"]\n", ").sort_values(by=\"duration_mean\", ascending=False)\n", "\n", "ggplot(by_genre_df, aes(\"duration\", \"genre\")) + \\\n", " geom_area_ridges(aes(group=\"genre\", fill=\"duration_mean\"), \\\n", " scale=4, sampling=sampling_pick(by_genre_df.shape[0]), \\\n", " tooltips=layer_tooltips().title(\"@genre\")\\\n", " .line(\"@|@duration\")) + \\\n", " scale_x_log10() + \\\n", " scale_fill_viridis(name=\"mean duration\", option='plasma') + \\\n", " ggsize(800, 600) + \\\n", " ggtitle(\"Mean Netflix movie duration\") + \\\n", " theme(axis_line_x='blank')" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "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.10.13" } }, "nbformat": 4, "nbformat_minor": 5 }