From 4d1a872f2fb06cdff15dc5fa509e6732dbaf7a51 Mon Sep 17 00:00:00 2001 From: Chanin Nantasenamat <51851491+dataprofessor@users.noreply.github.com> Date: Tue, 12 Nov 2024 20:18:24 -0800 Subject: [PATCH 1/6] Add files via upload --- python/google_colab_first_notebook.ipynb | 983 +++++++++++++++++++++++ 1 file changed, 983 insertions(+) create mode 100644 python/google_colab_first_notebook.ipynb diff --git a/python/google_colab_first_notebook.ipynb b/python/google_colab_first_notebook.ipynb new file mode 100644 index 0000000..13386f1 --- /dev/null +++ b/python/google_colab_first_notebook.ipynb @@ -0,0 +1,983 @@ +{ + "nbformat": 4, + "nbformat_minor": 0, + "metadata": { + "colab": { + "provenance": [] + }, + "kernelspec": { + "name": "python3", + "display_name": "Python 3" + }, + "language_info": { + "name": "python" + } + }, + "cells": [ + { + "cell_type": "markdown", + "source": [ + "# My First Notebook\n" + ], + "metadata": { + "id": "yWsgD4dxrhSX" + } + }, + { + "cell_type": "markdown", + "source": [ + "# H1 heading" + ], + "metadata": { + "id": "zRVndNmir2M4" + } + }, + { + "cell_type": "markdown", + "source": [ + "## H2 heading" + ], + "metadata": { + "id": "ByuA1cDmrqhb" + } + }, + { + "cell_type": "markdown", + "source": [ + "### H3 heading" + ], + "metadata": { + "id": "HM0mR4v4sAXP" + } + }, + { + "cell_type": "markdown", + "source": [ + "# Load API key" + ], + "metadata": { + "id": "qC1RLhLKwswk" + } + }, + { + "cell_type": "code", + "source": [ + "from google.colab import userdata\n", + "dummy_api_key = userdata.get('DUMMY_KEY')" + ], + "metadata": { + "id": "8idhWq95wgKl" + }, + "execution_count": null, + "outputs": [] + }, + { + "cell_type": "markdown", + "source": [ + "# Examples" + ], + "metadata": { + "id": "ECEbeZCFsIh5" + } + }, + { + "cell_type": "markdown", + "source": [ + "## pandas" + ], + "metadata": { + "id": "RmJPQguLsKip" + } + }, + { + "cell_type": "code", + "source": [ + "import pandas as pd" + ], + "metadata": { + "id": "dw1W26YmroA8" + }, + "execution_count": null, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "df = pd.read_csv('sample_data/california_housing_test.csv')\n", + "df.head()" + ], + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/", + "height": 206 + }, + "id": "wGnYqBtFsPnf", + "outputId": "d4142036-ab13-4905-856a-aa8f4ee3d17b" + }, + "execution_count": null, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + " longitude latitude housing_median_age total_rooms total_bedrooms \\\n", + "0 -122.05 37.37 27.0 3885.0 661.0 \n", + "1 -118.30 34.26 43.0 1510.0 310.0 \n", + "2 -117.81 33.78 27.0 3589.0 507.0 \n", + "3 -118.36 33.82 28.0 67.0 15.0 \n", + "4 -119.67 36.33 19.0 1241.0 244.0 \n", + "\n", + " population households median_income median_house_value \n", + "0 1537.0 606.0 6.6085 344700.0 \n", + "1 809.0 277.0 3.5990 176500.0 \n", + "2 1484.0 495.0 5.7934 270500.0 \n", + "3 49.0 11.0 6.1359 330000.0 \n", + "4 850.0 237.0 2.9375 81700.0 " + ], + "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", + "
longitudelatitudehousing_median_agetotal_roomstotal_bedroomspopulationhouseholdsmedian_incomemedian_house_value
0-122.0537.3727.03885.0661.01537.0606.06.6085344700.0
1-118.3034.2643.01510.0310.0809.0277.03.5990176500.0
2-117.8133.7827.03589.0507.01484.0495.05.7934270500.0
3-118.3633.8228.067.015.049.011.06.1359330000.0
4-119.6736.3319.01241.0244.0850.0237.02.937581700.0
\n", + "
\n", + "
\n", + "\n", + "
\n", + " \n", + "\n", + " \n", + "\n", + " \n", + "
\n", + "\n", + "\n", + "
\n", + " \n", + "\n", + "\n", + "\n", + " \n", + "
\n", + "\n", + "
\n", + "
\n" + ], + "application/vnd.google.colaboratory.intrinsic+json": { + "type": "dataframe", + "variable_name": "df", + "summary": "{\n \"name\": \"df\",\n \"rows\": 3000,\n \"fields\": [\n {\n \"column\": \"longitude\",\n \"properties\": {\n \"dtype\": \"number\",\n \"std\": 1.9949362939550161,\n \"min\": -124.18,\n \"max\": -114.49,\n \"num_unique_values\": 607,\n \"samples\": [\n -121.15,\n -121.46,\n -121.02\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"latitude\",\n \"properties\": {\n \"dtype\": \"number\",\n \"std\": 2.1296695233438325,\n \"min\": 32.56,\n \"max\": 41.92,\n \"num_unique_values\": 587,\n \"samples\": [\n 40.17,\n 33.69,\n 39.61\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"housing_median_age\",\n \"properties\": {\n \"dtype\": \"number\",\n \"std\": 12.555395554955755,\n \"min\": 1.0,\n \"max\": 52.0,\n \"num_unique_values\": 52,\n \"samples\": [\n 14.0,\n 49.0,\n 7.0\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"total_rooms\",\n \"properties\": {\n \"dtype\": \"number\",\n \"std\": 2155.59333162558,\n \"min\": 6.0,\n \"max\": 30450.0,\n \"num_unique_values\": 2215,\n \"samples\": [\n 1961.0,\n 1807.0,\n 680.0\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"total_bedrooms\",\n \"properties\": {\n \"dtype\": \"number\",\n \"std\": 415.6543681363232,\n \"min\": 2.0,\n \"max\": 5419.0,\n \"num_unique_values\": 1055,\n \"samples\": [\n 532.0,\n 764.0,\n 2162.0\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"population\",\n \"properties\": {\n \"dtype\": \"number\",\n \"std\": 1030.5430124122422,\n \"min\": 5.0,\n \"max\": 11935.0,\n \"num_unique_values\": 1802,\n \"samples\": [\n 947.0,\n 1140.0,\n 2019.0\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"households\",\n \"properties\": {\n \"dtype\": \"number\",\n \"std\": 365.42270980552604,\n \"min\": 2.0,\n \"max\": 4930.0,\n \"num_unique_values\": 1026,\n \"samples\": [\n 646.0,\n 629.0,\n 504.0\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"median_income\",\n \"properties\": {\n \"dtype\": \"number\",\n \"std\": 1.854511729691481,\n \"min\": 0.4999,\n \"max\": 15.0001,\n \"num_unique_values\": 2578,\n \"samples\": [\n 1.725,\n 0.7403,\n 2.6964\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"median_house_value\",\n \"properties\": {\n \"dtype\": \"number\",\n \"std\": 113119.68746964433,\n \"min\": 22500.0,\n \"max\": 500001.0,\n \"num_unique_values\": 1784,\n \"samples\": [\n 71900.0,\n 63000.0,\n 115800.0\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n }\n ]\n}" + } + }, + "metadata": {}, + "execution_count": 5 + } + ] + }, + { + "cell_type": "code", + "source": [ + "df.shape" + ], + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "8YBEQ5ZPtyRu", + "outputId": "b23eb485-b7f6-477f-b515-d46fedc41dca" + }, + "execution_count": null, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "(3000, 9)" + ] + }, + "metadata": {}, + "execution_count": 10 + } + ] + }, + { + "cell_type": "markdown", + "source": [ + "## yt-dlp" + ], + "metadata": { + "id": "dthivj-_sn_w" + } + }, + { + "cell_type": "code", + "source": [ + "! apt-get install ffmpeg" + ], + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "BKdcB7l-vz_h", + "outputId": "16893d68-2951-49d0-96d2-c3653d6a44fb" + }, + "execution_count": null, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "Reading package lists... Done\n", + "Building dependency tree... Done\n", + "Reading state information... Done\n", + "ffmpeg is already the newest version (7:4.4.2-0ubuntu0.22.04.1).\n", + "0 upgraded, 0 newly installed, 0 to remove and 49 not upgraded.\n" + ] + } + ] + }, + { + "cell_type": "code", + "source": [ + "pip install yt-dlp" + ], + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "VegGCtSaspMK", + "outputId": "06c0b539-dc12-4eda-bb42-8231ebb8ec75" + }, + "execution_count": null, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "Collecting yt-dlp\n", + " Downloading yt_dlp-2024.11.4-py3-none-any.whl.metadata (172 kB)\n", + "\u001b[?25l \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m0.0/172.1 kB\u001b[0m \u001b[31m?\u001b[0m eta \u001b[36m-:--:--\u001b[0m\r\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m172.1/172.1 kB\u001b[0m \u001b[31m5.0 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[?25hDownloading yt_dlp-2024.11.4-py3-none-any.whl (3.2 MB)\n", + "\u001b[?25l \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m0.0/3.2 MB\u001b[0m \u001b[31m?\u001b[0m eta \u001b[36m-:--:--\u001b[0m\r\u001b[2K \u001b[91m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[90m╺\u001b[0m\u001b[90m━━━━━━\u001b[0m \u001b[32m2.6/3.2 MB\u001b[0m \u001b[31m69.6 MB/s\u001b[0m eta \u001b[36m0:00:01\u001b[0m\r\u001b[2K \u001b[91m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[91m╸\u001b[0m \u001b[32m3.2/3.2 MB\u001b[0m \u001b[31m65.8 MB/s\u001b[0m eta \u001b[36m0:00:01\u001b[0m\r\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m3.2/3.2 MB\u001b[0m \u001b[31m33.7 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[?25hInstalling collected packages: yt-dlp\n", + "Successfully installed yt-dlp-2024.11.4\n" + ] + } + ] + }, + { + "cell_type": "code", + "source": [ + "import yt_dlp\n", + "\n", + "def download_audio(url):\n", + " ydl_opts = {\n", + " 'format': 'bestaudio/best',\n", + " 'postprocessors': [{\n", + " 'key': 'FFmpegExtractAudio',\n", + " 'preferredcodec': 'mp3',\n", + " 'preferredquality': '192',\n", + " }],\n", + " 'outtmpl': '%(title)s.%(ext)s',\n", + " 'verbose': True, # Add this line\n", + " }\n", + "\n", + " with yt_dlp.YoutubeDL(ydl_opts) as ydl:\n", + " ydl.download([url])" + ], + "metadata": { + "id": "NYJ03kwms7TY" + }, + "execution_count": null, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "URL = \"https://www.youtube.com/watch?v=UF8uR6Z6KLc\"\n", + "download_audio(URL)" + ], + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "wMM6oBSks8FZ", + "outputId": "d17918c9-7196-4aa4-83f8-1780a0739df7" + }, + "execution_count": null, + "outputs": [ + { + "output_type": "stream", + "name": "stderr", + "text": [ + "[debug] Encodings: locale UTF-8, fs utf-8, pref UTF-8, out UTF-8 (No ANSI), error UTF-8 (No ANSI), screen UTF-8 (No ANSI)\n", + "[debug] yt-dlp version stable@2024.11.04 from yt-dlp/yt-dlp [197d0b03b] (pip) API\n", + "[debug] params: {'format': 'bestaudio/best', 'postprocessors': [{'key': 'FFmpegExtractAudio', 'preferredcodec': 'mp3', 'preferredquality': '192'}], 'outtmpl': '%(title)s.%(ext)s', 'verbose': True, 'compat_opts': set(), 'http_headers': {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36', 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8', 'Accept-Language': 'en-us,en;q=0.5', 'Sec-Fetch-Mode': 'navigate'}}\n", + "[debug] Python 3.10.12 (CPython x86_64 64bit) - Linux-6.1.85+-x86_64-with-glibc2.35 (OpenSSL 3.0.2 15 Mar 2022, glibc 2.35)\n", + "[debug] exe versions: ffmpeg 4.4.2 (setts), ffprobe 4.4.2\n", + "[debug] Optional libraries: certifi-2024.08.30, requests-2.32.3, secretstorage-3.3.1, sqlite3-3.37.2, urllib3-2.2.3\n", + "[debug] Proxy map: {'colab_language_server': '/usr/colab/bin/language_service'}\n", + "[debug] Request Handlers: urllib, requests\n", + "[debug] Loaded 1838 extractors\n" + ] + }, + { + "output_type": "stream", + "name": "stdout", + "text": [ + "[youtube] Extracting URL: https://www.youtube.com/watch?v=UF8uR6Z6KLc\n", + "[youtube] UF8uR6Z6KLc: Downloading webpage\n", + "[youtube] UF8uR6Z6KLc: Downloading ios player API JSON\n", + "[youtube] UF8uR6Z6KLc: Downloading mweb player API JSON\n", + "[youtube] UF8uR6Z6KLc: Downloading player 4e23410d\n" + ] + }, + { + "output_type": "stream", + "name": "stderr", + "text": [ + "[debug] Saving youtube-nsig.4e23410d to cache\n", + "[debug] [youtube] Decrypted nsig TODInL2VkpwBeZYW7 => wBKo3X3nM8BmSA\n", + "[debug] Loading youtube-nsig.4e23410d from cache\n", + "[debug] [youtube] Decrypted nsig vAeQv-NfW6cUtSuNm => 9nN6xXoPuOaU-A\n" + ] + }, + { + "output_type": "stream", + "name": "stdout", + "text": [ + "[youtube] UF8uR6Z6KLc: Downloading m3u8 information\n" + ] + }, + { + "output_type": "stream", + "name": "stderr", + "text": [ + "[debug] Sort order given by extractor: quality, res, fps, hdr:12, source, vcodec, channels, acodec, lang, proto\n", + "[debug] Formats sorted by: hasvid, ie_pref, quality, res, fps, hdr:12(7), source, vcodec, channels, acodec, lang, proto, size, br, asr, vext, aext, hasaud, id\n" + ] + }, + { + "output_type": "stream", + "name": "stdout", + "text": [ + "[info] UF8uR6Z6KLc: Downloading 1 format(s): 251\n" + ] + }, + { + "output_type": "stream", + "name": "stderr", + "text": [ + "[debug] Invoking http downloader on \"https://rr1---sn-qxo7rn7r.googlevideo.com/videoplayback?expire=1730771008&ei=4CMpZ4XhJpPBsfIP7deLmAo&ip=35.199.188.39&id=o-APTN0lKEb0Qfe0Jq0HNmcfAnPmHCwQ_vTDUQ-grBegFk&itag=251&source=youtube&requiressl=yes&xpc=EgVo2aDSNQ%3D%3D&met=1730749408%2C&mh=-6&mm=31%2C26&mn=sn-qxo7rn7r%2Csn-a5mekndl&ms=au%2Conr&mv=m&mvi=1&pl=20&rms=au%2Cau&vprv=1&svpuc=1&mime=audio%2Fwebm&rqh=1&gir=yes&clen=11436231&dur=904.241&lmt=1727658751589050&mt=1730749051&fvip=3&keepalive=yes&fexp=51312688%2C51326932&c=IOS&txp=4532434&sparams=expire%2Cei%2Cip%2Cid%2Citag%2Csource%2Crequiressl%2Cxpc%2Cvprv%2Csvpuc%2Cmime%2Crqh%2Cgir%2Cclen%2Cdur%2Clmt&sig=AJfQdSswRAIgdyRaqQwBtuq6sm2qQrZRZtYbW8LoccP0YWy2R9hHK70CIE3HXpRHAOJFUukFaZHGV2uQ-Sk6VmPSgZ74DwmAQICb&lsparams=met%2Cmh%2Cmm%2Cmn%2Cms%2Cmv%2Cmvi%2Cpl%2Crms&lsig=ACJ0pHgwRQIhAI2cNPYa2PUX70RTEbQQjQVfq6JLIv8EL0Te68Yfpqn-AiAOWu5_w37ZFpinBi-6Xt70X5Mdhlv6iviwRj7LeGV7Cg%3D%3D\"\n" + ] + }, + { + "output_type": "stream", + "name": "stdout", + "text": [ + "[download] Destination: Steve Jobs' 2005 Stanford Commencement Address.webm\n", + "[download] 100% of 10.91MiB in 00:00:00 at 22.43MiB/s \n" + ] + }, + { + "output_type": "stream", + "name": "stderr", + "text": [ + "[debug] ffmpeg command line: ffprobe -show_streams 'file:Steve Jobs'\"'\"' 2005 Stanford Commencement Address.webm'\n" + ] + }, + { + "output_type": "stream", + "name": "stdout", + "text": [ + "[ExtractAudio] Destination: Steve Jobs' 2005 Stanford Commencement Address.mp3\n" + ] + }, + { + "output_type": "stream", + "name": "stderr", + "text": [ + "[debug] ffmpeg command line: ffmpeg -y -loglevel repeat+info -i 'file:Steve Jobs'\"'\"' 2005 Stanford Commencement Address.webm' -vn -acodec libmp3lame -b:a 192.0k -movflags +faststart 'file:Steve Jobs'\"'\"' 2005 Stanford Commencement Address.mp3'\n" + ] + }, + { + "output_type": "stream", + "name": "stdout", + "text": [ + "Deleting original file Steve Jobs' 2005 Stanford Commencement Address.webm (pass -k to keep)\n" + ] + } + ] + }, + { + "cell_type": "markdown", + "source": [ + "## scikit-learn" + ], + "metadata": { + "id": "gHB4HINduElj" + } + }, + { + "cell_type": "code", + "source": [ + "pip install scikit-learn -U" + ], + "metadata": { + "id": "7A1yCVNlutQ_" + }, + "execution_count": null, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "from sklearn.datasets import make_hastie_10_2\n", + "from sklearn.ensemble import GradientBoostingClassifier\n", + "\n", + "X, y = make_hastie_10_2(random_state=0)\n", + "clf = GradientBoostingClassifier(n_estimators=100, learning_rate=1.0,\n", + " max_depth=1, random_state=0).fit(X, y)\n", + "clf.feature_importances_" + ], + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "KVIBZ62euF87", + "outputId": "1bc8f2b9-3eae-48c3-b44a-2b5d89d25e7e" + }, + "execution_count": null, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "array([0.10684213, 0.10461707, 0.11265447, 0.09863589, 0.09469133,\n", + " 0.10729306, 0.09163753, 0.09718194, 0.09581415, 0.09063242])" + ] + }, + "metadata": {}, + "execution_count": 11 + } + ] + }, + { + "cell_type": "markdown", + "source": [ + "## altair" + ], + "metadata": { + "id": "YFoTWdpdu_fV" + } + }, + { + "cell_type": "markdown", + "source": [ + "### Heatmap\n", + "\n", + "Here's how to create a Heatmap." + ], + "metadata": { + "id": "cAno9XZkvOor" + } + }, + { + "cell_type": "code", + "source": [ + "import altair as alt\n", + "import numpy as np\n", + "import pandas as pd\n", + "\n", + "# Compute x^2 + y^2 across a 2D grid\n", + "x, y = np.meshgrid(range(-5, 5), range(-5, 5))\n", + "z = x ** 2 + y ** 2\n", + "\n", + "# Convert this grid to columnar data expected by Altair\n", + "source = pd.DataFrame({'x': x.ravel(),\n", + " 'y': y.ravel(),\n", + " 'z': z.ravel()})\n", + "\n", + "alt.Chart(source).mark_rect().encode(\n", + " x='x:O',\n", + " y='y:O',\n", + " color='z:Q'\n", + ")" + ], + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/", + "height": 262 + }, + "id": "7NSe5rKiuG82", + "outputId": "c56c460c-5cde-4100-f91e-e1e44ece081f" + }, + "execution_count": null, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/html": [ + "\n", + "
\n", + "" + ], + "text/plain": [ + "alt.Chart(...)" + ] + }, + "metadata": {}, + "execution_count": 12 + } + ] + }, + { + "cell_type": "markdown", + "source": [ + "### Stacked Area Chart" + ], + "metadata": { + "id": "1sGwP2h9vaKw" + } + }, + { + "cell_type": "code", + "source": [ + "import altair as alt\n", + "from vega_datasets import data\n", + "\n", + "source = data.iowa_electricity()\n", + "\n", + "alt.Chart(source).mark_area().encode(\n", + " x=\"year:T\",\n", + " y=\"net_generation:Q\",\n", + " color=\"source:N\"\n", + ")" + ], + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/", + "height": 424 + }, + "id": "vDQc_4kLvH8l", + "outputId": "0c72c68a-d72e-4564-afe6-253793faf7a8" + }, + "execution_count": null, + "outputs": [ + { + "output_type": "stream", + "name": "stderr", + "text": [ + "/usr/local/lib/python3.10/dist-packages/altair/utils/core.py:384: FutureWarning: the convert_dtype parameter is deprecated and will be removed in a future version. Do ``ser.astype(object).apply()`` instead if you want ``convert_dtype=False``.\n", + " col = df[col_name].apply(to_list_if_array, convert_dtype=False)\n" + ] + }, + { + "output_type": "execute_result", + "data": { + "text/html": [ + "\n", + "
\n", + "" + ], + "text/plain": [ + "alt.Chart(...)" + ] + }, + "metadata": {}, + "execution_count": 13 + } + ] + }, + { + "cell_type": "code", + "source": [], + "metadata": { + "id": "xZ2fN6SLvMYe" + }, + "execution_count": null, + "outputs": [] + } + ] +} \ No newline at end of file From d494f8093073990fcf77061bd740a0e4c2d40020 Mon Sep 17 00:00:00 2001 From: Chanin Nantasenamat <51851491+dataprofessor@users.noreply.github.com> Date: Tue, 12 Nov 2024 20:19:44 -0800 Subject: [PATCH 2/6] Delete python/google_colab_first_notebook.ipynb --- python/google_colab_first_notebook.ipynb | 983 ----------------------- 1 file changed, 983 deletions(-) delete mode 100644 python/google_colab_first_notebook.ipynb diff --git a/python/google_colab_first_notebook.ipynb b/python/google_colab_first_notebook.ipynb deleted file mode 100644 index 13386f1..0000000 --- a/python/google_colab_first_notebook.ipynb +++ /dev/null @@ -1,983 +0,0 @@ -{ - "nbformat": 4, - "nbformat_minor": 0, - "metadata": { - "colab": { - "provenance": [] - }, - "kernelspec": { - "name": "python3", - "display_name": "Python 3" - }, - "language_info": { - "name": "python" - } - }, - "cells": [ - { - "cell_type": "markdown", - "source": [ - "# My First Notebook\n" - ], - "metadata": { - "id": "yWsgD4dxrhSX" - } - }, - { - "cell_type": "markdown", - "source": [ - "# H1 heading" - ], - "metadata": { - "id": "zRVndNmir2M4" - } - }, - { - "cell_type": "markdown", - "source": [ - "## H2 heading" - ], - "metadata": { - "id": "ByuA1cDmrqhb" - } - }, - { - "cell_type": "markdown", - "source": [ - "### H3 heading" - ], - "metadata": { - "id": "HM0mR4v4sAXP" - } - }, - { - "cell_type": "markdown", - "source": [ - "# Load API key" - ], - "metadata": { - "id": "qC1RLhLKwswk" - } - }, - { - "cell_type": "code", - "source": [ - "from google.colab import userdata\n", - "dummy_api_key = userdata.get('DUMMY_KEY')" - ], - "metadata": { - "id": "8idhWq95wgKl" - }, - "execution_count": null, - "outputs": [] - }, - { - "cell_type": "markdown", - "source": [ - "# Examples" - ], - "metadata": { - "id": "ECEbeZCFsIh5" - } - }, - { - "cell_type": "markdown", - "source": [ - "## pandas" - ], - "metadata": { - "id": "RmJPQguLsKip" - } - }, - { - "cell_type": "code", - "source": [ - "import pandas as pd" - ], - "metadata": { - "id": "dw1W26YmroA8" - }, - "execution_count": null, - "outputs": [] - }, - { - "cell_type": "code", - "source": [ - "df = pd.read_csv('sample_data/california_housing_test.csv')\n", - "df.head()" - ], - "metadata": { - "colab": { - "base_uri": "https://localhost:8080/", - "height": 206 - }, - "id": "wGnYqBtFsPnf", - "outputId": "d4142036-ab13-4905-856a-aa8f4ee3d17b" - }, - "execution_count": null, - "outputs": [ - { - "output_type": "execute_result", - "data": { - "text/plain": [ - " longitude latitude housing_median_age total_rooms total_bedrooms \\\n", - "0 -122.05 37.37 27.0 3885.0 661.0 \n", - "1 -118.30 34.26 43.0 1510.0 310.0 \n", - "2 -117.81 33.78 27.0 3589.0 507.0 \n", - "3 -118.36 33.82 28.0 67.0 15.0 \n", - "4 -119.67 36.33 19.0 1241.0 244.0 \n", - "\n", - " population households median_income median_house_value \n", - "0 1537.0 606.0 6.6085 344700.0 \n", - "1 809.0 277.0 3.5990 176500.0 \n", - "2 1484.0 495.0 5.7934 270500.0 \n", - "3 49.0 11.0 6.1359 330000.0 \n", - "4 850.0 237.0 2.9375 81700.0 " - ], - "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", - "
longitudelatitudehousing_median_agetotal_roomstotal_bedroomspopulationhouseholdsmedian_incomemedian_house_value
0-122.0537.3727.03885.0661.01537.0606.06.6085344700.0
1-118.3034.2643.01510.0310.0809.0277.03.5990176500.0
2-117.8133.7827.03589.0507.01484.0495.05.7934270500.0
3-118.3633.8228.067.015.049.011.06.1359330000.0
4-119.6736.3319.01241.0244.0850.0237.02.937581700.0
\n", - "
\n", - "
\n", - "\n", - "
\n", - " \n", - "\n", - " \n", - "\n", - " \n", - "
\n", - "\n", - "\n", - "
\n", - " \n", - "\n", - "\n", - "\n", - " \n", - "
\n", - "\n", - "
\n", - "
\n" - ], - "application/vnd.google.colaboratory.intrinsic+json": { - "type": "dataframe", - "variable_name": "df", - "summary": "{\n \"name\": \"df\",\n \"rows\": 3000,\n \"fields\": [\n {\n \"column\": \"longitude\",\n \"properties\": {\n \"dtype\": \"number\",\n \"std\": 1.9949362939550161,\n \"min\": -124.18,\n \"max\": -114.49,\n \"num_unique_values\": 607,\n \"samples\": [\n -121.15,\n -121.46,\n -121.02\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"latitude\",\n \"properties\": {\n \"dtype\": \"number\",\n \"std\": 2.1296695233438325,\n \"min\": 32.56,\n \"max\": 41.92,\n \"num_unique_values\": 587,\n \"samples\": [\n 40.17,\n 33.69,\n 39.61\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"housing_median_age\",\n \"properties\": {\n \"dtype\": \"number\",\n \"std\": 12.555395554955755,\n \"min\": 1.0,\n \"max\": 52.0,\n \"num_unique_values\": 52,\n \"samples\": [\n 14.0,\n 49.0,\n 7.0\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"total_rooms\",\n \"properties\": {\n \"dtype\": \"number\",\n \"std\": 2155.59333162558,\n \"min\": 6.0,\n \"max\": 30450.0,\n \"num_unique_values\": 2215,\n \"samples\": [\n 1961.0,\n 1807.0,\n 680.0\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"total_bedrooms\",\n \"properties\": {\n \"dtype\": \"number\",\n \"std\": 415.6543681363232,\n \"min\": 2.0,\n \"max\": 5419.0,\n \"num_unique_values\": 1055,\n \"samples\": [\n 532.0,\n 764.0,\n 2162.0\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"population\",\n \"properties\": {\n \"dtype\": \"number\",\n \"std\": 1030.5430124122422,\n \"min\": 5.0,\n \"max\": 11935.0,\n \"num_unique_values\": 1802,\n \"samples\": [\n 947.0,\n 1140.0,\n 2019.0\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"households\",\n \"properties\": {\n \"dtype\": \"number\",\n \"std\": 365.42270980552604,\n \"min\": 2.0,\n \"max\": 4930.0,\n \"num_unique_values\": 1026,\n \"samples\": [\n 646.0,\n 629.0,\n 504.0\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"median_income\",\n \"properties\": {\n \"dtype\": \"number\",\n \"std\": 1.854511729691481,\n \"min\": 0.4999,\n \"max\": 15.0001,\n \"num_unique_values\": 2578,\n \"samples\": [\n 1.725,\n 0.7403,\n 2.6964\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"median_house_value\",\n \"properties\": {\n \"dtype\": \"number\",\n \"std\": 113119.68746964433,\n \"min\": 22500.0,\n \"max\": 500001.0,\n \"num_unique_values\": 1784,\n \"samples\": [\n 71900.0,\n 63000.0,\n 115800.0\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n }\n ]\n}" - } - }, - "metadata": {}, - "execution_count": 5 - } - ] - }, - { - "cell_type": "code", - "source": [ - "df.shape" - ], - "metadata": { - "colab": { - "base_uri": "https://localhost:8080/" - }, - "id": "8YBEQ5ZPtyRu", - "outputId": "b23eb485-b7f6-477f-b515-d46fedc41dca" - }, - "execution_count": null, - "outputs": [ - { - "output_type": "execute_result", - "data": { - "text/plain": [ - "(3000, 9)" - ] - }, - "metadata": {}, - "execution_count": 10 - } - ] - }, - { - "cell_type": "markdown", - "source": [ - "## yt-dlp" - ], - "metadata": { - "id": "dthivj-_sn_w" - } - }, - { - "cell_type": "code", - "source": [ - "! apt-get install ffmpeg" - ], - "metadata": { - "colab": { - "base_uri": "https://localhost:8080/" - }, - "id": "BKdcB7l-vz_h", - "outputId": "16893d68-2951-49d0-96d2-c3653d6a44fb" - }, - "execution_count": null, - "outputs": [ - { - "output_type": "stream", - "name": "stdout", - "text": [ - "Reading package lists... Done\n", - "Building dependency tree... Done\n", - "Reading state information... Done\n", - "ffmpeg is already the newest version (7:4.4.2-0ubuntu0.22.04.1).\n", - "0 upgraded, 0 newly installed, 0 to remove and 49 not upgraded.\n" - ] - } - ] - }, - { - "cell_type": "code", - "source": [ - "pip install yt-dlp" - ], - "metadata": { - "colab": { - "base_uri": "https://localhost:8080/" - }, - "id": "VegGCtSaspMK", - "outputId": "06c0b539-dc12-4eda-bb42-8231ebb8ec75" - }, - "execution_count": null, - "outputs": [ - { - "output_type": "stream", - "name": "stdout", - "text": [ - "Collecting yt-dlp\n", - " Downloading yt_dlp-2024.11.4-py3-none-any.whl.metadata (172 kB)\n", - "\u001b[?25l \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m0.0/172.1 kB\u001b[0m \u001b[31m?\u001b[0m eta \u001b[36m-:--:--\u001b[0m\r\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m172.1/172.1 kB\u001b[0m \u001b[31m5.0 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", - "\u001b[?25hDownloading yt_dlp-2024.11.4-py3-none-any.whl (3.2 MB)\n", - "\u001b[?25l \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m0.0/3.2 MB\u001b[0m \u001b[31m?\u001b[0m eta \u001b[36m-:--:--\u001b[0m\r\u001b[2K \u001b[91m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[90m╺\u001b[0m\u001b[90m━━━━━━\u001b[0m \u001b[32m2.6/3.2 MB\u001b[0m \u001b[31m69.6 MB/s\u001b[0m eta \u001b[36m0:00:01\u001b[0m\r\u001b[2K \u001b[91m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[91m╸\u001b[0m \u001b[32m3.2/3.2 MB\u001b[0m \u001b[31m65.8 MB/s\u001b[0m eta \u001b[36m0:00:01\u001b[0m\r\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m3.2/3.2 MB\u001b[0m \u001b[31m33.7 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", - "\u001b[?25hInstalling collected packages: yt-dlp\n", - "Successfully installed yt-dlp-2024.11.4\n" - ] - } - ] - }, - { - "cell_type": "code", - "source": [ - "import yt_dlp\n", - "\n", - "def download_audio(url):\n", - " ydl_opts = {\n", - " 'format': 'bestaudio/best',\n", - " 'postprocessors': [{\n", - " 'key': 'FFmpegExtractAudio',\n", - " 'preferredcodec': 'mp3',\n", - " 'preferredquality': '192',\n", - " }],\n", - " 'outtmpl': '%(title)s.%(ext)s',\n", - " 'verbose': True, # Add this line\n", - " }\n", - "\n", - " with yt_dlp.YoutubeDL(ydl_opts) as ydl:\n", - " ydl.download([url])" - ], - "metadata": { - "id": "NYJ03kwms7TY" - }, - "execution_count": null, - "outputs": [] - }, - { - "cell_type": "code", - "source": [ - "URL = \"https://www.youtube.com/watch?v=UF8uR6Z6KLc\"\n", - "download_audio(URL)" - ], - "metadata": { - "colab": { - "base_uri": "https://localhost:8080/" - }, - "id": "wMM6oBSks8FZ", - "outputId": "d17918c9-7196-4aa4-83f8-1780a0739df7" - }, - "execution_count": null, - "outputs": [ - { - "output_type": "stream", - "name": "stderr", - "text": [ - "[debug] Encodings: locale UTF-8, fs utf-8, pref UTF-8, out UTF-8 (No ANSI), error UTF-8 (No ANSI), screen UTF-8 (No ANSI)\n", - "[debug] yt-dlp version stable@2024.11.04 from yt-dlp/yt-dlp [197d0b03b] (pip) API\n", - "[debug] params: {'format': 'bestaudio/best', 'postprocessors': [{'key': 'FFmpegExtractAudio', 'preferredcodec': 'mp3', 'preferredquality': '192'}], 'outtmpl': '%(title)s.%(ext)s', 'verbose': True, 'compat_opts': set(), 'http_headers': {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36', 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8', 'Accept-Language': 'en-us,en;q=0.5', 'Sec-Fetch-Mode': 'navigate'}}\n", - "[debug] Python 3.10.12 (CPython x86_64 64bit) - Linux-6.1.85+-x86_64-with-glibc2.35 (OpenSSL 3.0.2 15 Mar 2022, glibc 2.35)\n", - "[debug] exe versions: ffmpeg 4.4.2 (setts), ffprobe 4.4.2\n", - "[debug] Optional libraries: certifi-2024.08.30, requests-2.32.3, secretstorage-3.3.1, sqlite3-3.37.2, urllib3-2.2.3\n", - "[debug] Proxy map: {'colab_language_server': '/usr/colab/bin/language_service'}\n", - "[debug] Request Handlers: urllib, requests\n", - "[debug] Loaded 1838 extractors\n" - ] - }, - { - "output_type": "stream", - "name": "stdout", - "text": [ - "[youtube] Extracting URL: https://www.youtube.com/watch?v=UF8uR6Z6KLc\n", - "[youtube] UF8uR6Z6KLc: Downloading webpage\n", - "[youtube] UF8uR6Z6KLc: Downloading ios player API JSON\n", - "[youtube] UF8uR6Z6KLc: Downloading mweb player API JSON\n", - "[youtube] UF8uR6Z6KLc: Downloading player 4e23410d\n" - ] - }, - { - "output_type": "stream", - "name": "stderr", - "text": [ - "[debug] Saving youtube-nsig.4e23410d to cache\n", - "[debug] [youtube] Decrypted nsig TODInL2VkpwBeZYW7 => wBKo3X3nM8BmSA\n", - "[debug] Loading youtube-nsig.4e23410d from cache\n", - "[debug] [youtube] Decrypted nsig vAeQv-NfW6cUtSuNm => 9nN6xXoPuOaU-A\n" - ] - }, - { - "output_type": "stream", - "name": "stdout", - "text": [ - "[youtube] UF8uR6Z6KLc: Downloading m3u8 information\n" - ] - }, - { - "output_type": "stream", - "name": "stderr", - "text": [ - "[debug] Sort order given by extractor: quality, res, fps, hdr:12, source, vcodec, channels, acodec, lang, proto\n", - "[debug] Formats sorted by: hasvid, ie_pref, quality, res, fps, hdr:12(7), source, vcodec, channels, acodec, lang, proto, size, br, asr, vext, aext, hasaud, id\n" - ] - }, - { - "output_type": "stream", - "name": "stdout", - "text": [ - "[info] UF8uR6Z6KLc: Downloading 1 format(s): 251\n" - ] - }, - { - "output_type": "stream", - "name": "stderr", - "text": [ - "[debug] Invoking http downloader on \"https://rr1---sn-qxo7rn7r.googlevideo.com/videoplayback?expire=1730771008&ei=4CMpZ4XhJpPBsfIP7deLmAo&ip=35.199.188.39&id=o-APTN0lKEb0Qfe0Jq0HNmcfAnPmHCwQ_vTDUQ-grBegFk&itag=251&source=youtube&requiressl=yes&xpc=EgVo2aDSNQ%3D%3D&met=1730749408%2C&mh=-6&mm=31%2C26&mn=sn-qxo7rn7r%2Csn-a5mekndl&ms=au%2Conr&mv=m&mvi=1&pl=20&rms=au%2Cau&vprv=1&svpuc=1&mime=audio%2Fwebm&rqh=1&gir=yes&clen=11436231&dur=904.241&lmt=1727658751589050&mt=1730749051&fvip=3&keepalive=yes&fexp=51312688%2C51326932&c=IOS&txp=4532434&sparams=expire%2Cei%2Cip%2Cid%2Citag%2Csource%2Crequiressl%2Cxpc%2Cvprv%2Csvpuc%2Cmime%2Crqh%2Cgir%2Cclen%2Cdur%2Clmt&sig=AJfQdSswRAIgdyRaqQwBtuq6sm2qQrZRZtYbW8LoccP0YWy2R9hHK70CIE3HXpRHAOJFUukFaZHGV2uQ-Sk6VmPSgZ74DwmAQICb&lsparams=met%2Cmh%2Cmm%2Cmn%2Cms%2Cmv%2Cmvi%2Cpl%2Crms&lsig=ACJ0pHgwRQIhAI2cNPYa2PUX70RTEbQQjQVfq6JLIv8EL0Te68Yfpqn-AiAOWu5_w37ZFpinBi-6Xt70X5Mdhlv6iviwRj7LeGV7Cg%3D%3D\"\n" - ] - }, - { - "output_type": "stream", - "name": "stdout", - "text": [ - "[download] Destination: Steve Jobs' 2005 Stanford Commencement Address.webm\n", - "[download] 100% of 10.91MiB in 00:00:00 at 22.43MiB/s \n" - ] - }, - { - "output_type": "stream", - "name": "stderr", - "text": [ - "[debug] ffmpeg command line: ffprobe -show_streams 'file:Steve Jobs'\"'\"' 2005 Stanford Commencement Address.webm'\n" - ] - }, - { - "output_type": "stream", - "name": "stdout", - "text": [ - "[ExtractAudio] Destination: Steve Jobs' 2005 Stanford Commencement Address.mp3\n" - ] - }, - { - "output_type": "stream", - "name": "stderr", - "text": [ - "[debug] ffmpeg command line: ffmpeg -y -loglevel repeat+info -i 'file:Steve Jobs'\"'\"' 2005 Stanford Commencement Address.webm' -vn -acodec libmp3lame -b:a 192.0k -movflags +faststart 'file:Steve Jobs'\"'\"' 2005 Stanford Commencement Address.mp3'\n" - ] - }, - { - "output_type": "stream", - "name": "stdout", - "text": [ - "Deleting original file Steve Jobs' 2005 Stanford Commencement Address.webm (pass -k to keep)\n" - ] - } - ] - }, - { - "cell_type": "markdown", - "source": [ - "## scikit-learn" - ], - "metadata": { - "id": "gHB4HINduElj" - } - }, - { - "cell_type": "code", - "source": [ - "pip install scikit-learn -U" - ], - "metadata": { - "id": "7A1yCVNlutQ_" - }, - "execution_count": null, - "outputs": [] - }, - { - "cell_type": "code", - "source": [ - "from sklearn.datasets import make_hastie_10_2\n", - "from sklearn.ensemble import GradientBoostingClassifier\n", - "\n", - "X, y = make_hastie_10_2(random_state=0)\n", - "clf = GradientBoostingClassifier(n_estimators=100, learning_rate=1.0,\n", - " max_depth=1, random_state=0).fit(X, y)\n", - "clf.feature_importances_" - ], - "metadata": { - "colab": { - "base_uri": "https://localhost:8080/" - }, - "id": "KVIBZ62euF87", - "outputId": "1bc8f2b9-3eae-48c3-b44a-2b5d89d25e7e" - }, - "execution_count": null, - "outputs": [ - { - "output_type": "execute_result", - "data": { - "text/plain": [ - "array([0.10684213, 0.10461707, 0.11265447, 0.09863589, 0.09469133,\n", - " 0.10729306, 0.09163753, 0.09718194, 0.09581415, 0.09063242])" - ] - }, - "metadata": {}, - "execution_count": 11 - } - ] - }, - { - "cell_type": "markdown", - "source": [ - "## altair" - ], - "metadata": { - "id": "YFoTWdpdu_fV" - } - }, - { - "cell_type": "markdown", - "source": [ - "### Heatmap\n", - "\n", - "Here's how to create a Heatmap." - ], - "metadata": { - "id": "cAno9XZkvOor" - } - }, - { - "cell_type": "code", - "source": [ - "import altair as alt\n", - "import numpy as np\n", - "import pandas as pd\n", - "\n", - "# Compute x^2 + y^2 across a 2D grid\n", - "x, y = np.meshgrid(range(-5, 5), range(-5, 5))\n", - "z = x ** 2 + y ** 2\n", - "\n", - "# Convert this grid to columnar data expected by Altair\n", - "source = pd.DataFrame({'x': x.ravel(),\n", - " 'y': y.ravel(),\n", - " 'z': z.ravel()})\n", - "\n", - "alt.Chart(source).mark_rect().encode(\n", - " x='x:O',\n", - " y='y:O',\n", - " color='z:Q'\n", - ")" - ], - "metadata": { - "colab": { - "base_uri": "https://localhost:8080/", - "height": 262 - }, - "id": "7NSe5rKiuG82", - "outputId": "c56c460c-5cde-4100-f91e-e1e44ece081f" - }, - "execution_count": null, - "outputs": [ - { - "output_type": "execute_result", - "data": { - "text/html": [ - "\n", - "
\n", - "" - ], - "text/plain": [ - "alt.Chart(...)" - ] - }, - "metadata": {}, - "execution_count": 12 - } - ] - }, - { - "cell_type": "markdown", - "source": [ - "### Stacked Area Chart" - ], - "metadata": { - "id": "1sGwP2h9vaKw" - } - }, - { - "cell_type": "code", - "source": [ - "import altair as alt\n", - "from vega_datasets import data\n", - "\n", - "source = data.iowa_electricity()\n", - "\n", - "alt.Chart(source).mark_area().encode(\n", - " x=\"year:T\",\n", - " y=\"net_generation:Q\",\n", - " color=\"source:N\"\n", - ")" - ], - "metadata": { - "colab": { - "base_uri": "https://localhost:8080/", - "height": 424 - }, - "id": "vDQc_4kLvH8l", - "outputId": "0c72c68a-d72e-4564-afe6-253793faf7a8" - }, - "execution_count": null, - "outputs": [ - { - "output_type": "stream", - "name": "stderr", - "text": [ - "/usr/local/lib/python3.10/dist-packages/altair/utils/core.py:384: FutureWarning: the convert_dtype parameter is deprecated and will be removed in a future version. Do ``ser.astype(object).apply()`` instead if you want ``convert_dtype=False``.\n", - " col = df[col_name].apply(to_list_if_array, convert_dtype=False)\n" - ] - }, - { - "output_type": "execute_result", - "data": { - "text/html": [ - "\n", - "
\n", - "" - ], - "text/plain": [ - "alt.Chart(...)" - ] - }, - "metadata": {}, - "execution_count": 13 - } - ] - }, - { - "cell_type": "code", - "source": [], - "metadata": { - "id": "xZ2fN6SLvMYe" - }, - "execution_count": null, - "outputs": [] - } - ] -} \ No newline at end of file From b99bda9287a8f3c69d00f6fdd9f8f2bd2f68542c Mon Sep 17 00:00:00 2001 From: Chanin Nantasenamat <51851491+dataprofessor@users.noreply.github.com> Date: Sat, 10 Jan 2026 00:23:20 -0800 Subject: [PATCH 3/6] Update README.md --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index dd32105..520d3f4 100644 --- a/README.md +++ b/README.md @@ -9,3 +9,5 @@ Folder | Description [shiny](https://github.com/dataprofessor/code/tree/master/shiny) | Codes for building *web applications* in R with *shiny* package. > Note: More to come. Please stay tuned! + + From 1abd57fef5503f6d2693913e23cb268a5ad97e5a Mon Sep 17 00:00:00 2001 From: Chanin Nantasenamat <51851491+dataprofessor@users.noreply.github.com> Date: Sat, 10 Jan 2026 00:24:48 -0800 Subject: [PATCH 4/6] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 520d3f4..be0cfe5 100644 --- a/README.md +++ b/README.md @@ -10,4 +10,4 @@ Folder | Description > Note: More to come. Please stay tuned! - +** Subscribe to my Newsletter:** https://dataprofessor.beehiiv.com/ From 820a84022d66523efce6260ab2fd2e1b68f0a599 Mon Sep 17 00:00:00 2001 From: Chanin Nantasenamat <51851491+dataprofessor@users.noreply.github.com> Date: Sat, 10 Jan 2026 00:25:10 -0800 Subject: [PATCH 5/6] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index be0cfe5..2139429 100644 --- a/README.md +++ b/README.md @@ -10,4 +10,4 @@ Folder | Description > Note: More to come. Please stay tuned! -** Subscribe to my Newsletter:** https://dataprofessor.beehiiv.com/ +**Subscribe to my Newsletter:** https://dataprofessor.beehiiv.com/ From d05a1b139d03880269634926a2ca7d45538b1cbb Mon Sep 17 00:00:00 2001 From: Chanin Nantasenamat <51851491+dataprofessor@users.noreply.github.com> Date: Sat, 10 Jan 2026 00:25:58 -0800 Subject: [PATCH 6/6] Add sparkle emoji to newsletter subscription line --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 2139429..957e9e5 100644 --- a/README.md +++ b/README.md @@ -10,4 +10,4 @@ Folder | Description > Note: More to come. Please stay tuned! -**Subscribe to my Newsletter:** https://dataprofessor.beehiiv.com/ +✨ **Subscribe to my Newsletter:** https://dataprofessor.beehiiv.com/