{ "cells": [ { "cell_type": "markdown", "id": "03033b7a-ad2e-435b-9191-1d1929f697c9", "metadata": {}, "source": [ "# Sunshine Hours" ] }, { "cell_type": "code", "execution_count": 1, "id": "525d29b0-46e1-4a02-ab35-f0ca14563d7e", "metadata": { "execution": { "iopub.execute_input": "2024-08-23T10:44:11.330813Z", "iopub.status.busy": "2024-08-23T10:44:11.330698Z", "iopub.status.idle": "2024-08-23T10:44:11.658653Z", "shell.execute_reply": "2024-08-23T10:44:11.658311Z" } }, "outputs": [], "source": [ "from math import pi\n", "\n", "from lets_plot import *" ] }, { "cell_type": "code", "execution_count": 2, "id": "e7b870a4-b38f-40e8-b46a-2870a2b6b6f3", "metadata": { "execution": { "iopub.execute_input": "2024-08-23T10:44:11.660641Z", "iopub.status.busy": "2024-08-23T10:44:11.660433Z", "iopub.status.idle": "2024-08-23T10:44:11.662681Z", "shell.execute_reply": "2024-08-23T10:44:11.662493Z" } }, "outputs": [ { "data": { "text/html": [ "\n", "
\n", " \n", " " ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "LetsPlot.setup_html()" ] }, { "cell_type": "code", "execution_count": 3, "id": "95acc6a8-2802-437d-b753-8c3b690dff91", "metadata": { "execution": { "iopub.execute_input": "2024-08-23T10:44:11.664212Z", "iopub.status.busy": "2024-08-23T10:44:11.664129Z", "iopub.status.idle": "2024-08-23T10:44:11.665932Z", "shell.execute_reply": "2024-08-23T10:44:11.665739Z" } }, "outputs": [], "source": [ "shift = 15\n", "target_cities = [\"Barcelona\", \"New York City\", \"Lyon\", \"Paris\", \"Amsterdam\", \"Berlin\"]\n", "angles = {\n", " \"JAN\": -shift, \"FEB\": -30 - shift, \"MAR\": -60 - shift, \"APR\": 90 - shift, \"MAY\": 60 - shift, \"JUN\": 30 - shift,\n", " \"JUL\": -shift, \"AUG\": -30 - shift, \"SEP\": -60 - shift, \"OCT\": 90 - shift, \"NOV\": 60 - shift, \"DEC\": 30 - shift,\n", "}" ] }, { "cell_type": "code", "execution_count": 4, "id": "3cca9346-8e95-4efa-aa69-14177d3737a3", "metadata": { "execution": { "iopub.execute_input": "2024-08-23T10:44:11.667308Z", "iopub.status.busy": "2024-08-23T10:44:11.667227Z", "iopub.status.idle": "2024-08-23T10:44:11.669352Z", "shell.execute_reply": "2024-08-23T10:44:11.669159Z" } }, "outputs": [], "source": [ "def get_data(cities):\n", " import pandas as pd\n", " raw_df = pd.read_csv(\"https://raw.githubusercontent.com/JetBrains/lets-plot-docs/master/data/sunshine_hours.csv\")\n", " filtered_df = raw_df[raw_df[\"City\"].isin(cities)]\n", " df = pd.melt(filtered_df, id_vars=[\"Country\", \"City\"], value_vars=filtered_df.columns[2:-1], \\\n", " var_name=\"Month\", value_name=\"Sunshine hours\")\n", " df[\"Month\"] = df[\"Month\"].str.upper()\n", " df[\"Angle\"] = df[\"Month\"].apply(lambda m: angles[m])\n", " return df.sort_values(by=[\"City\"], key=lambda d: [target_cities.index(v) for i, v in d.items()]).reset_index(drop=True)" ] }, { "cell_type": "code", "execution_count": 5, "id": "2b525db5-451f-4b1c-badf-439e4cf0feb0", "metadata": { "execution": { "iopub.execute_input": "2024-08-23T10:44:11.670637Z", "iopub.status.busy": "2024-08-23T10:44:11.670564Z", "iopub.status.idle": "2024-08-23T10:44:12.021149Z", "shell.execute_reply": "2024-08-23T10:44:12.020946Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "(72, 5)\n" ] }, { "data": { "text/html": [ "\n", " | Country | \n", "City | \n", "Month | \n", "Sunshine hours | \n", "Angle | \n", "
---|---|---|---|---|---|
0 | \n", "Spain | \n", "Barcelona | \n", "AUG | \n", "264.0 | \n", "-45 | \n", "
1 | \n", "Spain | \n", "Barcelona | \n", "MAY | \n", "258.0 | \n", "45 | \n", "
2 | \n", "Spain | \n", "Barcelona | \n", "MAR | \n", "206.0 | \n", "-75 | \n", "