diff --git a/10. Working with datetime.ipynb b/10. Working with datetime.ipynb index fbe18e6..5139688 100644 --- a/10. Working with datetime.ipynb +++ b/10. Working with datetime.ipynb @@ -1,148 +1,282 @@ { - "cells": [ - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# Working with datetime\n", - "---\n", - "Numpy has core array data types which natively support datetime functionality. The data type is called “datetime64”, so named because “datetime” is already taken by the datetime library included in Python.\n" - ] + "nbformat": 4, + "nbformat_minor": 0, + "metadata": { + "colab": { + "name": "10. Working with datetime.ipynb", + "version": "0.3.2", + "provenance": [] + }, + "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.6.7" + }, + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + } }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "import numpy as np" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "YYYY-MM-DD" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# creating a date\n", - "today = np.datetime64('2017-12-31')" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "today" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# get year in numpy datetime object\n", - "np.datetime64(today, 'Y')" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# creating array of dates in a month\n", - "dates = np.arange('2019-01', '2020-02', dtype='datetime64[M]')" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "dates" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# arithmetic operation on dates\n", - "dur = np.datetime64('2018-05-22') - np.datetime64('2017-05-22')" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "dur" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# duration in weeks\n", - "np.timedelta64(dur, 'W')" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# sorting dates\n", - "a = np.array(['2017-02-12', '2016-10-13', '2019-05-22'], dtype='datetime64')" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "a" - ] - } - ], - "metadata": { - "kernelspec": { - "display_name": "Python 3", - "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.6.7" - } - }, - "nbformat": 4, - "nbformat_minor": 2 -} + "cells": [ + { + "cell_type": "markdown", + "metadata": { + "id": "FIwinC3trguJ", + "colab_type": "text" + }, + "source": [ + "# Working with datetime\n", + "---\n", + "Numpy has core array data types which natively support datetime functionality. The data type is called “datetime64”, so named because “datetime” is already taken by the datetime library included in Python.\n" + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "Am5LVH7_rguP", + "colab_type": "code", + "colab": {} + }, + "source": [ + "import numpy as np" + ], + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "metadata": { + "id": "EQsr1s8irguY", + "colab_type": "code", + "colab": {} + }, + "source": [ + "YYYY-MM-DD" + ], + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "metadata": { + "id": "zfAqIyWrrguf", + "colab_type": "code", + "colab": {} + }, + "source": [ + "# creating a date\n", + "today = np.datetime64('2017-12-31')" + ], + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "metadata": { + "id": "Sz5d19Srrguk", + "colab_type": "code", + "colab": {} + }, + "source": [ + "today" + ], + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "metadata": { + "id": "MayiCTEGrguq", + "colab_type": "code", + "colab": {} + }, + "source": [ + "# get year in numpy datetime object\n", + "np.datetime64(today, 'Y')" + ], + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "metadata": { + "id": "fA9gFfHarguu", + "colab_type": "code", + "colab": {} + }, + "source": [ + "# creating array of dates in a month\n", + "dates = np.arange('2019-01', '2020-02', dtype='datetime64[M]')" + ], + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "metadata": { + "id": "e9QYJKzXrguy", + "colab_type": "code", + "colab": {} + }, + "source": [ + "dates" + ], + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "metadata": { + "id": "L7IG23cOrgu6", + "colab_type": "code", + "colab": {} + }, + "source": [ + "# arithmetic operation on dates\n", + "dur = np.datetime64('2018-05-22') - np.datetime64('2017-05-22')" + ], + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "metadata": { + "id": "HfRyDQkyrgvC", + "colab_type": "code", + "colab": {} + }, + "source": [ + "dur" + ], + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "metadata": { + "id": "hfD62uKtrgvi", + "colab_type": "code", + "colab": {} + }, + "source": [ + "# duration in weeks\n", + "np.timedelta64(dur, 'W')" + ], + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "metadata": { + "id": "IOXP38yirgvr", + "colab_type": "code", + "colab": {} + }, + "source": [ + "# sorting dates\n", + "a = np.array(['2017-02-12', '2016-10-13', '2019-05-22'], dtype='datetime64')" + ], + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "metadata": { + "id": "iIEy1VoZrgv0", + "colab_type": "code", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 34 + }, + "outputId": "f9c1e68d-2e10-4544-e5a9-8b3cfa02b63d" + }, + "source": [ + "a" + ], + "execution_count": 3, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "array(['2017-02-12', '2016-10-13', '2019-05-22'], dtype='datetime64[D]')" + ] + }, + "metadata": { + "tags": [] + }, + "execution_count": 3 + } + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "IpI_ZqGrrplI", + "colab_type": "code", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 34 + }, + "outputId": "f7538e98-e9db-46b6-aa3b-0be7d910e3ae" + }, + "source": [ + "a.sort\n", + "a" + ], + "execution_count": 11, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "array(['2016-10-13', '2017-02-12', '2019-05-22'], dtype='datetime64[D]')" + ] + }, + "metadata": { + "tags": [] + }, + "execution_count": 11 + } + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "SVO7uEBZsKpL", + "colab_type": "code", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 34 + }, + "outputId": "c3df6d40-c9af-4207-81ab-9661e04bffaf" + }, + "source": [ + "np.flip(a,0)" + ], + "execution_count": 17, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "array(['2019-05-22', '2017-02-12', '2016-10-13'], dtype='datetime64[D]')" + ] + }, + "metadata": { + "tags": [] + }, + "execution_count": 17 + } + ] + } + ] +} \ No newline at end of file