{ "cells": [ { "cell_type": "code", "execution_count": 72, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'Frank'" ] }, "execution_count": 72, "metadata": {}, "output_type": "execute_result" } ], "source": [ "(walrus_name := \"Frank\")" ] }, { "cell_type": "code", "execution_count": 73, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "My favorite walrus is named Frank!\n" ] } ], "source": [ "walrus_name = \"Frank\"\n", "print(f'My favorite walrus is named {walrus_name}!')" ] }, { "cell_type": "code", "execution_count": 74, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "My favorite walrus is named Frank!\n" ] } ], "source": [ "walrus_name = \"Frank\"\n", "print(f'My favorite walrus is named {walrus_name}!')" ] }, { "cell_type": "code", "execution_count": 75, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Have you met the greatest of the walruses, Frank Ocean?\n" ] } ], "source": [ "walrus_name = \"Frank\"\n", "walrus_last_name = \"Ocean\"\n", "walrus_full_name = walrus_name + ' ' + walrus_last_name\n", "print(f'''Have you met the greatest of the walruses, {\n", " walrus_full_name}?''')" ] }, { "cell_type": "code", "execution_count": 76, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Have you met the greatest of the walruses,Frank Ocean?\n" ] } ], "source": [ "print(f'''Have you met the greatest of the walruses,{\n", " (walrus_full_name := (walrus_name := \"Frank\") +\n", " \" \" +\n", " (walrus_last_name := \"Ocean\")\n", " )\n", "}?''')" ] }, { "cell_type": "code", "execution_count": 77, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Have you met the greatest of the walruses, Frank Ocean\n" ] } ], "source": [ "walrus_name = \"Frank\"\n", "walrus_last_name = \"Ocean\"\n", "print(f'''Have you met the greatest of the walruses, {\n", " (walrus_full_name := walrus_name + \" \" + walrus_last_name)\n", "}''')" ] }, { "cell_type": "code", "execution_count": 78, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "64\n" ] } ], "source": [ "n = 8\n", "\n", "if((check:=n**2) >= 50):\n", " print(check)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "\n", "user_input = input(\"What's your favorite arctic mammal? > \")\n", "\n", "while user_input.lower() != 'walrus':\n", " print(f'{user_input} is WRONG!')\n", " user_input = input(\"What's your favorite arctic mammal? > \")" ] }, { "cell_type": "code", "execution_count": 80, "metadata": {}, "outputs": [], "source": [ "while (user_input := input(\"What's your favorite arctic mammal? > \").lower()) != 'walrus':\n", " print(f'{user_input} is WRONG!')" ] }, { "cell_type": "code", "execution_count": 81, "metadata": {}, "outputs": [], "source": [ "import pandas as pd" ] }, { "cell_type": "code", "execution_count": 82, "metadata": {}, "outputs": [ { "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", "
datenew_casescum_casesnew_deathcum_deathnew_recoveredcum_recoveredcum_active_cases
02020-01-301100001
12020-01-310100001
22020-02-010100001
32020-02-021200002
42020-02-031300003
\n", "
" ], "text/plain": [ " date new_cases cum_cases new_death cum_death new_recovered \\\n", "0 2020-01-30 1 1 0 0 0 \n", "1 2020-01-31 0 1 0 0 0 \n", "2 2020-02-01 0 1 0 0 0 \n", "3 2020-02-02 1 2 0 0 0 \n", "4 2020-02-03 1 3 0 0 0 \n", "\n", " cum_recovered cum_active_cases \n", "0 0 1 \n", "1 0 1 \n", "2 0 1 \n", "3 0 2 \n", "4 0 3 " ] }, "execution_count": 82, "metadata": {}, "output_type": "execute_result" } ], "source": [ "covid_daily_in = pd.read_csv('./COVID-19_India_Data.csv')\n", "covid_daily_in.head()" ] }, { "cell_type": "code", "execution_count": 83, "metadata": {}, "outputs": [], "source": [ "prev_day = 0\n", "covid_daily_in['calculated_cases'] = [\n", " abs(prev_day - (prev_day := cases)) for\n", " # we use abs() here because the prev_day\n", " # value has to be called before it's\n", " # reassigned, so the actual value comes\n", " # out negative, but this should work for\n", " # all cases, as long as there isn't a\n", " # Null value.\n", " cases in covid_daily_in['cum_cases']\n", " ]" ] }, { "cell_type": "code", "execution_count": 84, "metadata": {}, "outputs": [ { "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", "
datecum_casesnew_casescalculated_cases
02020-01-30111
12020-01-31100
22020-02-01100
32020-02-02211
42020-02-03311
...............
6362021-10-27342310301635116351
6372021-10-28342453371430714307
6382021-10-29342595521421514215
6392021-10-30342724921294012940
6402021-10-31342853991290712907
\n", "

641 rows × 4 columns

\n", "
" ], "text/plain": [ " date cum_cases new_cases calculated_cases\n", "0 2020-01-30 1 1 1\n", "1 2020-01-31 1 0 0\n", "2 2020-02-01 1 0 0\n", "3 2020-02-02 2 1 1\n", "4 2020-02-03 3 1 1\n", ".. ... ... ... ...\n", "636 2021-10-27 34231030 16351 16351\n", "637 2021-10-28 34245337 14307 14307\n", "638 2021-10-29 34259552 14215 14215\n", "639 2021-10-30 34272492 12940 12940\n", "640 2021-10-31 34285399 12907 12907\n", "\n", "[641 rows x 4 columns]" ] }, "execution_count": 84, "metadata": {}, "output_type": "execute_result" } ], "source": [ "covid_daily_in[['date','cum_cases','new_cases','calculated_cases']]" ] }, { "cell_type": "code", "execution_count": 85, "metadata": {}, "outputs": [], "source": [ "calculated_cases = [covid_daily_in['cum_cases'].iloc[0]]\n", "for i ,_case in enumerate(covid_daily_in['cum_cases'][1:]):\n", " calculated_cases.append(\n", " _case - covid_daily_in['cum_cases'].iloc[i]\n", " )\n", "covid_daily_in['calculated_cases'] = calculated_cases" ] }, { "cell_type": "code", "execution_count": 86, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "30.5 µs ± 39 ns per loop (mean ± std. dev. of 7 runs, 10000 loops each)\n" ] } ], "source": [ "%%timeit\n", "prev_day = 0\n", "[abs(prev_day - (prev_day := cases)) for cases in covid_daily_in['cum_cases']]" ] }, { "cell_type": "code", "execution_count": 87, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "1.7 ms ± 1.85 µs per loop (mean ± std. dev. of 7 runs, 1000 loops each)\n" ] } ], "source": [ "%%timeit\n", "calculated_cases = [covid_daily_in['cum_cases'].iloc[0]]\n", "for i ,_case in enumerate(covid_daily_in['cum_cases'][1:]):\n", " calculated_cases.append(\n", " _case - covid_daily_in['cum_cases'].iloc[i]\n", " )" ] } ], "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.9.13" }, "orig_nbformat": 4 }, "nbformat": 4, "nbformat_minor": 2 }