{
"cells": [
{
"cell_type": "markdown",
"id": "4a87b5ef",
"metadata": {},
"source": [
"--- \n",
" \n",
"\n",
"
Department of Data Science \n",
"Course: Tools and Techniques for Data Science \n",
"\n",
"---\n",
"Instructor: Muhammad Arif Butt, Ph.D.
"
]
},
{
"cell_type": "markdown",
"id": "ab0dc25c",
"metadata": {},
"source": [
"Lecture 3.20 (Pandas-12) "
]
},
{
"cell_type": "markdown",
"id": "e2e9e8c5",
"metadata": {},
"source": [
" "
]
},
{
"cell_type": "markdown",
"id": "19f82705",
"metadata": {},
"source": [
" \n",
"\n",
"## _Working with Time Series Data_\n",
"\n",
"**Read Documentation for details:** \n",
"https://pandas.pydata.org/docs/user_guide/timeseries.html#overview"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "b153b19a",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "5f2f60b8",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "7109496b",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "a9e20ddb",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": 1,
"id": "ec33647f",
"metadata": {},
"outputs": [],
"source": [
"# To install this library in Jupyter notebook\n",
"#import sys\n",
"#!{sys.executable} -m pip install pandas"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "671d3985",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"('1.4.1',\n",
" ['/Users/arif/opt/anaconda3/envs/python10/lib/python3.10/site-packages/pandas'])"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"import pandas as pd\n",
"pd.__version__ , pd.__path__"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "24e3f49c",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "ae69a7b9",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "3daf1a87",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "8dcbafbd",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"id": "12db95e1",
"metadata": {},
"source": [
"## Learning agenda of this notebook\n",
"1. Recap of Python's Built-in Time and Datetime Modules\n",
" - Python Time module\n",
" - Python Datetime module\n",
" - Time Zones\n",
"2. Overview of Pandas Time Series Data Structures\n",
"3. Converting Strings to Pandas DateTime64 type\n",
" - Convert a Scalar String to DateTime\n",
" - Convert Pandas Series to DateTime\n",
" - Handling Issues of DateTime Formats\n",
" - Convert a Single Integer to Pandas DateTime\n",
"4. Practicing with a Simple Dataset\n",
"5. Practicing with UFO Dataset\n",
"6. Practicing with Crypto-Currency Dataset\n",
"7. Bonus:"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "3d3af656",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "c63ececf",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "b2e8052c",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "c8ce0dd8",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "d2f1c77f",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"id": "cf573669",
"metadata": {},
"source": [
"## Overview of Time Series Data\n",
"#### What is Time Series Data?\n",
"- Time series data, also referred to as time-stamped data, is a sequence of data recorded at specific intervals of time (can be monthly, daily, hourly, ....).\n",
"- These data points are analyzed to forecast the future.\n",
"- It is time dependent.\n",
"- Time series data is effected by four components:\n",
" - **Trend:** Increase or decrease in the series over a period of time. It persist over a long period of time. For Example, population growth of a country over years\n",
" - **Seasonality:** Regular patterns of up and down fluctuations, e.g., Sale of icecream increases in every summer\n",
" - **Cyclicity:** Variations that are caused at irregular intervals. Forexample, 5 years of economic growth, followed by 3 years of recession, followed by 7 years of economic growth, followed. by 1 year of recession\n",
" - **Irregularity:** It refers to variations which occur due to unpredictable factors and also do not repeat in particular patterns. For examples, fluctuations caused by earthquakes, floods, wars, etc\n",
" \n",
"#### What is time series Analysis?\n",
"- Time series analysis is the use of statistical methods to analyze time series data and extract meaningful statistics and characteristics about the data. Time series analysis helps identify trends, cycles, and seasonal variances to aid in the forecasting of a future event.\n",
"- Time series analysis can be useful to see how a given variable changes over time (while time itself, in time series data, is often the independent variable). Time series analysis can also be used to examine how the changes associated with the chosen data point compare to shifts in other variables over the same time period."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "d2413820",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "93b17f62",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "e642f910",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "0a04df60",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"id": "30308522",
"metadata": {},
"source": [
"## 1. Recap of Python Modules Related to Date and Time"
]
},
{
"cell_type": "markdown",
"id": "1a058d60",
"metadata": {},
"source": [
"## a. Python Time Module\n",
"- Python Time module is principally for working with UNIX time stamps; expressed as a floating point number taken to be seconds since the unix epoch (00:00:00 UTC on 1 January 1970)"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "64a13665",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"['_STRUCT_TM_ITEMS', '__doc__', '__loader__', '__name__', '__package__', '__spec__', 'altzone', 'asctime', 'ctime', 'daylight', 'get_clock_info', 'gmtime', 'localtime', 'mktime', 'monotonic', 'monotonic_ns', 'perf_counter', 'perf_counter_ns', 'process_time', 'process_time_ns', 'sleep', 'strftime', 'strptime', 'struct_time', 'time', 'time_ns', 'timezone', 'tzname', 'tzset']\n"
]
}
],
"source": [
"# Use `dir()` to get the list of methods in the Python `time` module\n",
"import time\n",
"print(dir(time))"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "6e181cdd",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "8459a6de",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "0da747cd",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "f704287d",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "b7c7db69",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"id": "911697e9",
"metadata": {},
"source": [
"**(i) The `time.time()` method returns the current time in seconds since UNIX Epoch (00:00:00 UTC on 1 January 1970)**"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "d0fa8a98",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"1645623933.013344"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"seconds = time.time()\n",
"seconds"
]
},
{
"cell_type": "markdown",
"id": "9ee734d8",
"metadata": {},
"source": [
"> You can achieve the same using the system `date` command and passing it `+%s` command line arugment"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "5cc8b863",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"1645623933\r\n"
]
}
],
"source": [
"!date +%s"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "83d89815",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "48e7a924",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "5f1587c0",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "ef8bc3c0",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "34cc80ff",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"id": "39132701",
"metadata": {},
"source": [
"**(ii) The `time.ctime()` method returns a date time string corresponding to the number of seconds passed to it since UNIX Epoch.**"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "70d0bb12",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'Thu Jan 1 05:00:00 1970'"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Showing `+5:00` hours time delta because of local time zone (PKT) differs from UTC with 5 hours\n",
"dtg1 = time.ctime(0)\n",
"dtg1"
]
},
{
"cell_type": "code",
"execution_count": 7,
"id": "3e3bb56a",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'Wed Feb 23 18:45:33 2022'"
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"#If you pass the current elapsed seconds since UNIX epoch to the `ctime()` method, it returns current datetime\n",
"seconds = time.time()\n",
"dtg2 = time.ctime(seconds)\n",
"dtg2"
]
},
{
"cell_type": "code",
"execution_count": 8,
"id": "6431482c",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Wed Feb 23 18:45:33 PKT 2022\r\n"
]
}
],
"source": [
"#Get time using shell command\n",
"!date"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "78a88a21",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "abe89e6c",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "815d83fd",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "56b95f64",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "5e47340a",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "54006989",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"id": "9445c4b5",
"metadata": {},
"source": [
"## b. Python Datetime Module\n",
"The `datetime` module can support many of the same operations as `time` module, but provides a more object oriented set of types, and also has some limited support for time zones as well."
]
},
{
"cell_type": "code",
"execution_count": 9,
"id": "121ebc36",
"metadata": {
"scrolled": true
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"['MAXYEAR', 'MINYEAR', '__all__', '__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__spec__', 'date', 'datetime', 'datetime_CAPI', 'sys', 'time', 'timedelta', 'timezone', 'tzinfo']\n"
]
}
],
"source": [
"# use dir() to get the list of complete functions in datetime module\n",
"import datetime\n",
"print(dir(datetime))"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "f544498b",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "33aa7221",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"id": "09c0b7b2",
"metadata": {},
"source": [
"**(i) The `datetime.datetime(year, month, day[, hour[, minute[, second[, microsecond[,tzinfo]]]]])` method is used to create any random date, along with time**"
]
},
{
"cell_type": "code",
"execution_count": 10,
"id": "929a2bc2",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"2021-12-31 00:00:00\n",
"\n"
]
}
],
"source": [
"dtg = datetime.datetime(2021,12,31)\n",
"print(dtg)\n",
"print(type(dtg))"
]
},
{
"cell_type": "code",
"execution_count": 11,
"id": "dd1869b6",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"2021-12-31 04:30:54.000678\n"
]
}
],
"source": [
"print(datetime.datetime(2021, 12, 31, 4, 30, 54, 678))"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "a46febb5",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "992d4a09",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"id": "5b197019",
"metadata": {},
"source": [
"**(ii) The `time([hour[, minute[, second[, microsecond[, tzinfo]]]]]) ` methods returns a time object. All arguments are optional**"
]
},
{
"cell_type": "code",
"execution_count": 12,
"id": "b4c51969",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"10:15:00\n",
"\n"
]
}
],
"source": [
"t1 = datetime.time(10, 15)\n",
"print(t1)\n",
"print(type(t1))"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "d1e210f4",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "f9e7146d",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"id": "b4ddbdda",
"metadata": {},
"source": [
"**(iii) You can explore some commonly used attributes related with the ``.**\n",
"- `dtg.year:` returns the year\n",
"- `dtg.month:` returns the month\n",
"- `dtg.day:` returns the date\n",
"- `dtg.hour:` returns the hour\n",
"- `dtg.minute:` returns the minutes\n",
"- `dtg.second:` returns the seconds"
]
},
{
"cell_type": "code",
"execution_count": 13,
"id": "a9cac04f",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"2021-12-31 04:25:58\n",
"\n"
]
}
],
"source": [
"dtg = datetime.datetime(2021, 12, 31, 4, 25, 58)\n",
"print(dtg)\n",
"print(type(dtg))"
]
},
{
"cell_type": "code",
"execution_count": 14,
"id": "7fb3b193",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"2021"
]
},
"execution_count": 14,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"dtg.year"
]
},
{
"cell_type": "code",
"execution_count": 15,
"id": "0fe16a1d",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"12"
]
},
"execution_count": 15,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"dtg.month"
]
},
{
"cell_type": "code",
"execution_count": 16,
"id": "4c20a73c",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"31"
]
},
"execution_count": 16,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"dtg.day"
]
},
{
"cell_type": "code",
"execution_count": 17,
"id": "a5d9ffcb",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"4"
]
},
"execution_count": 17,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"dtg.hour"
]
},
{
"cell_type": "code",
"execution_count": 18,
"id": "99a1c2e7",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"25"
]
},
"execution_count": 18,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"dtg.minute"
]
},
{
"cell_type": "code",
"execution_count": 19,
"id": "50e73280",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"58"
]
},
"execution_count": 19,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"dtg.second"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "2acd54e1",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "28946f80",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "db4c9e9f",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "8adc7c68",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "65f05563",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "e63806ac",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "f76a57ac",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "3ece3d07",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "344873f3",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"id": "18438927",
"metadata": {},
"source": [
"### c. Time Zones:\n",
"\n",
" \n",
"\n",
"- Since noon happens at different times in different parts of the world, therefore, the world is divided in different time zones.\n",
"- On Mac, Linux, and Windows operating systems, the information about these time zones is kept in files.\n",
"- Let me show you the contents of these files on my Mac system"
]
},
{
"cell_type": "code",
"execution_count": 20,
"id": "caa5d76b",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'Thu Jan 1 05:00:00 1970'"
]
},
"execution_count": 20,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# The UNIX Epoch in system local time is five hours ahead of mid night 1st Jan 1970\n",
"# (Coordinated Universal Time a successor to Greenwich Mean Time)\n",
"dtg1 = time.ctime(0)\n",
"dtg1"
]
},
{
"cell_type": "markdown",
"id": "c8098a53",
"metadata": {},
"source": [
"> You may have noticed that above cell does not display the exact UNIX epoch, i.e., mid-night 1st January 1970 rather is 5 hours ahead. This is because my machine is configured as per the time zone of Pakistan having a `+5:00` timedelta from Cooridnated Universtal Time (UTC a successor to GMT)"
]
},
{
"cell_type": "code",
"execution_count": 21,
"id": "1333e296",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"+VERSION \u001b[34mCanada\u001b[m\u001b[m GB Iran NZ-CHAT UCT\r\n",
"\u001b[34mAfrica\u001b[m\u001b[m \u001b[34mChile\u001b[m\u001b[m GB-Eire Israel Navajo \u001b[34mUS\u001b[m\u001b[m\r\n",
"\u001b[34mAmerica\u001b[m\u001b[m Cuba GMT Jamaica PRC UTC\r\n",
"\u001b[34mAntarctica\u001b[m\u001b[m EET GMT+0 Japan PST8PDT Universal\r\n",
"\u001b[34mArctic\u001b[m\u001b[m EST GMT-0 Kwajalein \u001b[34mPacific\u001b[m\u001b[m W-SU\r\n",
"\u001b[34mAsia\u001b[m\u001b[m EST5EDT GMT0 Libya Poland WET\r\n",
"\u001b[34mAtlantic\u001b[m\u001b[m Egypt Greenwich MET Portugal Zulu\r\n",
"\u001b[34mAustralia\u001b[m\u001b[m Eire HST MST ROC iso3166.tab\r\n",
"\u001b[34mBrazil\u001b[m\u001b[m \u001b[34mEtc\u001b[m\u001b[m Hongkong MST7MDT ROK leapseconds\r\n",
"CET \u001b[34mEurope\u001b[m\u001b[m Iceland \u001b[34mMexico\u001b[m\u001b[m Singapore posixrules\r\n",
"CST6CDT Factory \u001b[34mIndian\u001b[m\u001b[m NZ Turkey zone.tab\r\n"
]
}
],
"source": [
"!ls /usr/share/zoneinfo/"
]
},
{
"cell_type": "code",
"execution_count": 22,
"id": "4a57581c",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Aden Chongqing Jerusalem Novokuznetsk Tashkent\r\n",
"Almaty Chungking Kabul Novosibirsk Tbilisi\r\n",
"Amman Colombo Kamchatka Omsk Tehran\r\n",
"Anadyr Dacca Karachi Oral Tel_Aviv\r\n",
"Aqtau Damascus Kashgar Phnom_Penh Thimbu\r\n",
"Aqtobe Dhaka Kathmandu Pontianak Thimphu\r\n",
"Ashgabat Dili Katmandu Pyongyang Tokyo\r\n",
"Ashkhabad Dubai Khandyga Qatar Tomsk\r\n",
"Atyrau Dushanbe Kolkata Qostanay Ujung_Pandang\r\n",
"Baghdad Famagusta Krasnoyarsk Qyzylorda Ulaanbaatar\r\n",
"Bahrain Gaza Kuala_Lumpur Rangoon Ulan_Bator\r\n",
"Baku Harbin Kuching Riyadh Urumqi\r\n",
"Bangkok Hebron Kuwait Saigon Ust-Nera\r\n",
"Barnaul Ho_Chi_Minh Macao Sakhalin Vientiane\r\n",
"Beirut Hong_Kong Macau Samarkand Vladivostok\r\n",
"Bishkek Hovd Magadan Seoul Yakutsk\r\n",
"Brunei Irkutsk Makassar Shanghai Yangon\r\n",
"Calcutta Istanbul Manila Singapore Yekaterinburg\r\n",
"Chita Jakarta Muscat Srednekolymsk Yerevan\r\n",
"Choibalsan Jayapura Nicosia Taipei\r\n"
]
}
],
"source": [
"!ls /usr/share/zoneinfo/Asia"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "0263a5c6",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "921fed43",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "9e127fbc",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "6086280e",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "28b459e1",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "4718752b",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"id": "9250cda6",
"metadata": {},
"source": [
">On all UNIX based systems (Mac, Linux), `TZ` is an environment variable that can be set to any of the above files to get the date of that appropriate zone. By default the system is configured to set it to the local time of the country"
]
},
{
"cell_type": "code",
"execution_count": 23,
"id": "1fa0d04a",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Wed Feb 23 18:45:33 PKT 2022\r\n"
]
}
],
"source": [
"! date"
]
},
{
"cell_type": "code",
"execution_count": 24,
"id": "0c065ca5",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Wed Feb 23 18:45:33 PKT 2022\r\n"
]
}
],
"source": [
"! TZ=Asia/Karachi date"
]
},
{
"cell_type": "code",
"execution_count": 25,
"id": "60366a50",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Wed Feb 23 19:15:33 IST 2022\r\n"
]
}
],
"source": [
"! TZ=Asia/Calcutta date"
]
},
{
"cell_type": "code",
"execution_count": 26,
"id": "f1e5d015",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Wed Feb 23 18:45:33 +05 2022\r\n"
]
}
],
"source": [
"! TZ=Asia/Tashkent date"
]
},
{
"cell_type": "markdown",
"id": "0190d588",
"metadata": {},
"source": [
">So you can observe if we run `date` command after setting the TZ variable to Karachi and Calcutta, their local date times are displayed. Being in different time zones Pakistan Standard Time is 30 minutes before India"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "bd322c36",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "972b03ad",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "1f1b1c72",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "989d9343",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"id": "024a390f",
"metadata": {},
"source": [
"## 2. Overview of Pandas Time Series Data Structures\n",
"- **Timestamp & DatetimeIndex:**\n",
" - A `Timestamp` refer to particular moment in time, e.g., 28 July, 1969 at 11:00 am\n",
" - It is a replacement of Python's built-in datetime object\n",
" - The `pd.to_datetime()` method is used to create a `Timestamp` object\n",
" - The `pd.date_range()` method is used to generate a `DatetimeIndex` object\n",
"- **Period & PeriodIndex:**\n",
" - A `Period` refer to length of time between a start and end point, with each interval of uniform length\n",
" - The `pd.to_period()` method is used to create a `Period` object\n",
" - The `pd.period_range()` method is used to create a `PeriodIndex`\n",
"- **Timedelta & TimedeltaIndex:**\n",
" - A `Timedelta` or duration refer to an exact length of time, e.g., a duration of 235.54 seconds\n",
" - A `Timedelta` is created when you subtract two dates, while a `TimedeltaIndex` is created when you subtract two Periods"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "19c35812",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "d4ca6ead",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"id": "46b16d5a",
"metadata": {},
"source": [
"## 3. Converting Strings to Pandas Timestamp Object\n",
"- Pandas `pd.to_datetime()` method is used to convert its only required argument `arg` to a Timestamp object.\n",
"\n",
"```\n",
"pd.to_datetime(arg, format=None, errors='raise', unit=None, origin='unix')\n",
"```\n",
"- Where,\n",
" - `arg` can be a string, Series, int, datetime, list, tuple, 1-d array, DataFrame/dict-like object to convert\n",
" - `errors` {‘ignore’, ‘raise’, ‘coerce’}, default ‘raise’\n",
" - If `raise`, then invalid parsing will raise an exception.\n",
" - If `coerce`, then invalid parsing will be set as NaT.\n",
" - If `ignore`, then invalid parsing will return the input\n",
" - `format`: Used if the `arg` is not in the format as expected by the method\n",
" - `unit`: Used if the `arg` is integer and can be (D,s,ms,us,ns) passed since `origin` (default is `ns`)\n",
" - `origin`: is the reference point from where you want to start counting your units from. The default value of `origin` is the UNIX epoch."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "c17e7df2",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "07747255",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"id": "82b72df9",
"metadata": {},
"source": [
"### a. Convert a Scalar String to Timestamp"
]
},
{
"cell_type": "code",
"execution_count": 27,
"id": "a0f45498",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"2022-03-06 08:30:15\n",
"\n"
]
}
],
"source": [
"#YYYY-MM-DD\n",
"import pandas as pd\n",
"str_date = '2022-03-06 08:30:15'\n",
"print(str_date)\n",
"print(type(str_date))"
]
},
{
"cell_type": "code",
"execution_count": 28,
"id": "177a51a0",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"2022-03-06 08:30:15\n",
"\n"
]
}
],
"source": [
"ts = pd.to_datetime(str_date)\n",
"print(ts)\n",
"print(type(ts))"
]
},
{
"cell_type": "markdown",
"id": "817f6812",
"metadata": {},
"source": [
"**`pd.Timestamp Attributes`**\n",
"\n",
"`Series.dt.[ts.]second`: Returns seconds\n",
"\n",
"`ts.minute`: Returns year\n",
"\n",
"`ts.hour`: Returns hour\n",
"\n",
"`ts.day`: Returns day\n",
"\n",
"`ts.month`: Returns month as January=1, December=12\n",
"\n",
"`ts.year`: Returns the year of datetime object\n",
"\n",
"`Series.dt.day_name()`: Returns name of the day as string\n",
"\n",
"`Series.dt.month_name()`: Returns month as string\n",
"\n",
"For details Read: https://pandas.pydata.org/docs/reference/api/pandas.Series.dt.year.html"
]
},
{
"cell_type": "code",
"execution_count": 29,
"id": "a863d8ce",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"2022"
]
},
"execution_count": 29,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"ts.year"
]
},
{
"cell_type": "code",
"execution_count": 30,
"id": "829ca9af",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"3"
]
},
"execution_count": 30,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"ts.month"
]
},
{
"cell_type": "code",
"execution_count": 31,
"id": "85564ddb",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"6"
]
},
"execution_count": 31,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"ts.day"
]
},
{
"cell_type": "code",
"execution_count": 32,
"id": "eb6d073e",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'March'"
]
},
"execution_count": 32,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"ts.month_name()"
]
},
{
"cell_type": "code",
"execution_count": 33,
"id": "55482bf8",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"8"
]
},
"execution_count": 33,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"ts.hour"
]
},
{
"cell_type": "code",
"execution_count": 34,
"id": "6490fee1",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"30"
]
},
"execution_count": 34,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"ts.minute"
]
},
{
"cell_type": "code",
"execution_count": 35,
"id": "95852744",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"1"
]
},
"execution_count": 35,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"ts.quarter"
]
},
{
"cell_type": "markdown",
"id": "57df2339",
"metadata": {},
"source": [
">You can pass a list of strings containing dates to `pd.to_datetime()`, which will return a `DatetimeIndex` object"
]
},
{
"cell_type": "code",
"execution_count": 36,
"id": "34603f8a",
"metadata": {},
"outputs": [],
"source": [
"# If there is a invalid string that cannot be converted to a valid date, you will get an error\n",
"#pd.to_datetime(['2017-01-05', 'Jan 6, 2017', 'abc'])"
]
},
{
"cell_type": "code",
"execution_count": 37,
"id": "531f0b9b",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"DatetimeIndex(['2017-01-05', '2017-01-06', 'NaT'], dtype='datetime64[ns]', freq=None)"
]
},
"execution_count": 37,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Use `errors=coerce` to translate the remaining data and keep `NaT` for invalid string\n",
"pd.to_datetime(['2017-01-05', 'Jan 6, 2017', 'abc'], errors='coerce')"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "e0826324",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "d543b639",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "fedd9485",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "08878c89",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "6ca04171",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "ee9498dc",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"id": "4b289460",
"metadata": {},
"source": [
"### b. Convert Pandas Series of Strings to Series of Timestamps"
]
},
{
"cell_type": "code",
"execution_count": 38,
"id": "4efb47fb",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"0 2022-03-06 08:30\n",
"1 2022/03/06 08:30\n",
"2 6 March, 2022 08:30\n",
"3 Mar 06, 2022 08:30\n",
"4 202203060830\n",
"dtype: object"
]
},
"execution_count": 38,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# A pandas series having same date but in different formats\n",
"s1 = pd.Series(['2022-03-06 08:30', '2022/03/06 08:30', '6 March, 2022 08:30', 'Mar 06, 2022 08:30', '202203060830'])\n",
"type(s1)\n",
"s1"
]
},
{
"cell_type": "code",
"execution_count": 39,
"id": "a6e6b90d",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"0 2022-03-06 08:30:00\n",
"1 2022-03-06 08:30:00\n",
"2 2022-03-06 08:30:00\n",
"3 2022-03-06 08:30:00\n",
"4 2022-03-06 08:30:00\n",
"dtype: datetime64[ns]"
]
},
"execution_count": 39,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# to_datetime() function will convert all these different formats into a common format\n",
"s2 = pd.to_datetime(s1)\n",
"s2"
]
},
{
"cell_type": "code",
"execution_count": 40,
"id": "56db6352",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"pandas.core.series.Series"
]
},
"execution_count": 40,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"type(s2)"
]
},
{
"cell_type": "code",
"execution_count": 41,
"id": "5ec54b33",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"pandas._libs.tslibs.timestamps.Timestamp"
]
},
"execution_count": 41,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"type(s2[0])"
]
},
{
"cell_type": "code",
"execution_count": 42,
"id": "e1f2c22e",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"(6, 3)"
]
},
"execution_count": 42,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"s2[0].day, s2[0].month"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "e8fe752d",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "b9b02eec",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "b690b86a",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "3d30d249",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"id": "54687d75",
"metadata": {},
"source": [
"### c. Handling Issues of DateTime Formats\n",
"From above examples, it appears that `pd.to_datetime()` works fine for all date formats. Let us try storing 6 March, 2022 as '06/03/2022' or '06-03-2022'"
]
},
{
"cell_type": "markdown",
"id": "f9562539",
"metadata": {},
"source": [
"**(i) Problem 1:**"
]
},
{
"cell_type": "code",
"execution_count": 43,
"id": "55610b05",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"Timestamp('2022-06-03 00:00:00')"
]
},
"execution_count": 43,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"ts = pd.to_datetime('06-03-2022')\n",
"ts"
]
},
{
"cell_type": "code",
"execution_count": 44,
"id": "4155d90e",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"(3, 6)"
]
},
"execution_count": 44,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"ts.day, ts.month"
]
},
{
"cell_type": "markdown",
"id": "ea4f7153",
"metadata": {},
"source": [
"**Oops!**, Pandas `to_datetime()` method has converted the string to datetime, but interpreted it as 3 June 2022\n",
">The `pd.to_datetime()` by default, will parse string with month first (MM/DD, MM DD, or MM-DD) format"
]
},
{
"cell_type": "code",
"execution_count": 45,
"id": "5c252a91",
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"/var/folders/1t/g3ylw8h50cjdqmk5d6jh1qmm0000gn/T/ipykernel_11456/3152508908.py:2: UserWarning: Parsing '26-03-2022' in DD/MM/YYYY format. Provide format or specify infer_datetime_format=True for consistent parsing.\n",
" ts = pd.to_datetime('26-03-2022')\n"
]
},
{
"data": {
"text/plain": [
"(26, 3)"
]
},
"execution_count": 45,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Intelligence\n",
"ts = pd.to_datetime('26-03-2022')\n",
"ts.day, ts.month"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "41faab35",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"id": "2de68cd0",
"metadata": {},
"source": [
"**(ii) Problem 2:**"
]
},
{
"cell_type": "code",
"execution_count": 46,
"id": "85a11bf7",
"metadata": {},
"outputs": [],
"source": [
"#ts = pd.to_datetime('2022-03-06 08-PM')"
]
},
{
"cell_type": "markdown",
"id": "2b6213ee",
"metadata": {},
"source": [
"**Oops again**!, Pandas `to_datetime()` method has raised an error saying `ParserError: Unknown string format: 2022-03-06 08-PM`\n",
">It seems that `pd.to_datetime()` expects the time to be in 24 hours clock and not if the time is mentioned using AM (Ante-Meridiem meaning before Midday) or PM (Post-Meridiem, meaning after midday)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "8d49ed90",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "4295b54f",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "9110939b",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"id": "768fc152",
"metadata": {},
"source": [
"**(iii) Solution of above two Problems:**\n",
">Pass an appropriate `format string` to the `format` argument of the `pd.to_datetime()` method. The format string need to be prepared as per the string date format.\n",
"Visit this link to see for Format codes: https://pandas.pydata.org/docs/reference/api/pandas.Period.strftime.html"
]
},
{
"cell_type": "code",
"execution_count": 47,
"id": "9edd954d",
"metadata": {},
"outputs": [],
"source": [
"# Passing appropriate format string will resolve above two problems\n",
"ts = pd.to_datetime('06-03-2022 08-PM', format = '%d-%m-%Y %I-%p')"
]
},
{
"cell_type": "code",
"execution_count": 48,
"id": "f1a596e0",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"Timestamp('2022-03-06 20:00:00')"
]
},
"execution_count": 48,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"ts"
]
},
{
"cell_type": "code",
"execution_count": 49,
"id": "2e121dd3",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"(6, 3)"
]
},
"execution_count": 49,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"ts.day, ts.month"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "55ef2e7e",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "a00c1a82",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "0f5a2246",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "82c1a490",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "2102f083",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "d6aca85e",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "3a61f282",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"id": "dc8b9a70",
"metadata": {},
"source": [
"### d. Convert a Single Integer to Pandas Timestamp\n",
"- Pandas `pd.to_datetime()` method can also be used to convert the first argument passed as integer to Pandas `Timestamp` object. \n",
"- The `unit` argument tells about the unit of the `arg`, and it can be seconds, days or years\n",
"- The `origin` argument can be any reference point from where you want to start counting your units from. The default value of `origin` is the UNIX epoch.\n",
"```\n",
"pd.to_datetime(arg, format=None, unit=None, origin='unix')\n",
"```"
]
},
{
"cell_type": "code",
"execution_count": 50,
"id": "2868bcdd",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"1645623934\r\n"
]
}
],
"source": [
"!date +%s"
]
},
{
"cell_type": "code",
"execution_count": 51,
"id": "a6c7d1ae",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"Timestamp('1970-01-20 01:06:34.235000')"
]
},
"execution_count": 51,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"ts = pd.to_datetime(1645594235, unit='ms', origin='unix')\n",
"ts"
]
},
{
"cell_type": "markdown",
"id": "c2f45869",
"metadata": {},
"source": [
">You can mention the origin as some other reference point of your choice"
]
},
{
"cell_type": "code",
"execution_count": 52,
"id": "ed64ab8f",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"Timestamp('2022-01-11 00:00:00')"
]
},
"execution_count": 52,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"ts = pd.to_datetime(10, unit='D', origin='2022-01-01')\n",
"ts"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "a536c17e",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "4744af7f",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "c4118d99",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "e8021bec",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "072c792d",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "d16d2b3f",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "c9946871",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "b0a3269f",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"id": "7cef1736",
"metadata": {},
"source": [
"## 4. Practicing with a Simple Dataset"
]
},
{
"cell_type": "markdown",
"id": "20aab3ac",
"metadata": {},
"source": [
"### a. Option 1: Read the Dataset as such and then convert the Column Datatype to Timestamp64"
]
},
{
"cell_type": "markdown",
"id": "ad199219",
"metadata": {},
"source": [
"**Example 1:** A dataset with datetime in a format as expected by `pd.to_datetime()`"
]
},
{
"cell_type": "code",
"execution_count": 53,
"id": "87f58d21",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"name,dob,address,gender\r",
"\r\n",
"Khurram,2022-03-06 21:10,Lahore,Male\r",
"\r\n",
"Fatima,2022/03/06 08:30,Islamabad,Female\r",
"\r\n",
"Huzaifa,2022-03-06 20:15,Karachi,Male\r",
"\r\n",
"Shaista,2022.03.06 18:05,Peshawer,Female"
]
}
],
"source": [
"# yyyy-mm-dd hr:min\n",
"! cat datasets/datetime1.csv"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "3e62ef56",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": 54,
"id": "cf30ab52",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
"
\n",
" \n",
" \n",
" \n",
" name \n",
" dob \n",
" address \n",
" gender \n",
" \n",
" \n",
" \n",
" \n",
" 0 \n",
" Khurram \n",
" 2022-03-06 21:10 \n",
" Lahore \n",
" Male \n",
" \n",
" \n",
" 1 \n",
" Fatima \n",
" 2022/03/06 08:30 \n",
" Islamabad \n",
" Female \n",
" \n",
" \n",
" 2 \n",
" Huzaifa \n",
" 2022-03-06 20:15 \n",
" Karachi \n",
" Male \n",
" \n",
" \n",
" 3 \n",
" Shaista \n",
" 2022.03.06 18:05 \n",
" Peshawer \n",
" Female \n",
" \n",
" \n",
"
\n",
"
"
],
"text/plain": [
" name dob address gender\n",
"0 Khurram 2022-03-06 21:10 Lahore Male\n",
"1 Fatima 2022/03/06 08:30 Islamabad Female\n",
"2 Huzaifa 2022-03-06 20:15 Karachi Male\n",
"3 Shaista 2022.03.06 18:05 Peshawer Female"
]
},
"execution_count": 54,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"import pandas as pd\n",
"df = pd.read_csv(\"datasets/datetime1.csv\")\n",
"df"
]
},
{
"cell_type": "code",
"execution_count": 55,
"id": "1705cd65",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"name object\n",
"dob object\n",
"address object\n",
"gender object\n",
"dtype: object"
]
},
"execution_count": 55,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df.dtypes"
]
},
{
"cell_type": "code",
"execution_count": 56,
"id": "ac6fe6bc",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"0 2022-03-06 21:10\n",
"1 2022/03/06 08:30\n",
"2 2022-03-06 20:15\n",
"3 2022.03.06 18:05\n",
"Name: dob, dtype: object"
]
},
"execution_count": 56,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df.loc[:,'dob']"
]
},
{
"cell_type": "code",
"execution_count": 57,
"id": "018e2eee",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"0 2022-03-06 21:10:00\n",
"1 2022-03-06 08:30:00\n",
"2 2022-03-06 20:15:00\n",
"3 2022-03-06 18:05:00\n",
"Name: dob, dtype: datetime64[ns]"
]
},
"execution_count": 57,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"pd.to_datetime(df.loc[:,'dob'])"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "c6dadf1b",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": 58,
"id": "9605e3d3",
"metadata": {},
"outputs": [],
"source": [
"df['dob'] = pd.to_datetime(df.loc[:,'dob'])"
]
},
{
"cell_type": "code",
"execution_count": 59,
"id": "c37da731",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"name object\n",
"dob datetime64[ns]\n",
"address object\n",
"gender object\n",
"dtype: object"
]
},
"execution_count": 59,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df.dtypes"
]
},
{
"cell_type": "code",
"execution_count": 60,
"id": "406f2536",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
"
\n",
" \n",
" \n",
" \n",
" name \n",
" dob \n",
" address \n",
" gender \n",
" \n",
" \n",
" \n",
" \n",
" 0 \n",
" Khurram \n",
" 2022-03-06 21:10:00 \n",
" Lahore \n",
" Male \n",
" \n",
" \n",
" 1 \n",
" Fatima \n",
" 2022-03-06 08:30:00 \n",
" Islamabad \n",
" Female \n",
" \n",
" \n",
" 2 \n",
" Huzaifa \n",
" 2022-03-06 20:15:00 \n",
" Karachi \n",
" Male \n",
" \n",
" \n",
" 3 \n",
" Shaista \n",
" 2022-03-06 18:05:00 \n",
" Peshawer \n",
" Female \n",
" \n",
" \n",
"
\n",
"
"
],
"text/plain": [
" name dob address gender\n",
"0 Khurram 2022-03-06 21:10:00 Lahore Male\n",
"1 Fatima 2022-03-06 08:30:00 Islamabad Female\n",
"2 Huzaifa 2022-03-06 20:15:00 Karachi Male\n",
"3 Shaista 2022-03-06 18:05:00 Peshawer Female"
]
},
"execution_count": 60,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "0d7f14a1",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "40b62137",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"id": "f1c4cea9",
"metadata": {},
"source": [
"**Example 2:** A dataset with datetime in a format NOT expected by `pd.to_datetime()`"
]
},
{
"cell_type": "code",
"execution_count": 61,
"id": "2aba0c34",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"name,dob,address,gender\r",
"\r\n",
"Khurram,02-07-1980 08-PM,Lahore,Male\r",
"\r\n",
"Fatima,15-06-2001 06-AM,Islamabad,Female\r",
"\r\n",
"Huzaifa,08-04-1999 05-PM,Karachi,Male\r",
"\r\n",
"Shaista,10-09-2005 02-AM,Peshawer,Female"
]
}
],
"source": [
"# dd-mm-yyyy hr-PM\n",
"! cat datasets/datetime2.csv"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "b2548571",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": 62,
"id": "0ced9b12",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
"
\n",
" \n",
" \n",
" \n",
" name \n",
" dob \n",
" address \n",
" gender \n",
" \n",
" \n",
" \n",
" \n",
" 0 \n",
" Khurram \n",
" 02-07-1980 08-PM \n",
" Lahore \n",
" Male \n",
" \n",
" \n",
" 1 \n",
" Fatima \n",
" 15-06-2001 06-AM \n",
" Islamabad \n",
" Female \n",
" \n",
" \n",
" 2 \n",
" Huzaifa \n",
" 08-04-1999 05-PM \n",
" Karachi \n",
" Male \n",
" \n",
" \n",
" 3 \n",
" Shaista \n",
" 10-09-2005 02-AM \n",
" Peshawer \n",
" Female \n",
" \n",
" \n",
"
\n",
"
"
],
"text/plain": [
" name dob address gender\n",
"0 Khurram 02-07-1980 08-PM Lahore Male\n",
"1 Fatima 15-06-2001 06-AM Islamabad Female\n",
"2 Huzaifa 08-04-1999 05-PM Karachi Male\n",
"3 Shaista 10-09-2005 02-AM Peshawer Female"
]
},
"execution_count": 62,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df = pd.read_csv(\"datasets/datetime2.csv\")\n",
"df"
]
},
{
"cell_type": "code",
"execution_count": 63,
"id": "fbd41e0a",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"name object\n",
"dob object\n",
"address object\n",
"gender object\n",
"dtype: object"
]
},
"execution_count": 63,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df.dtypes"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "9b4a525b",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "eed6a046",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": 64,
"id": "b41321fb",
"metadata": {},
"outputs": [],
"source": [
"# Following LOC will now generate `ParserError: Unknown string format: 02-07-1980 08-PM`\n",
"#pd.to_datetime(df.loc[:,'dob'])"
]
},
{
"cell_type": "code",
"execution_count": 65,
"id": "766eb80f",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"0 1980-07-02 20:00:00\n",
"1 2001-06-15 06:00:00\n",
"2 1999-04-08 17:00:00\n",
"3 2005-09-10 02:00:00\n",
"Name: dob, dtype: datetime64[ns]"
]
},
"execution_count": 65,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"pd.to_datetime(df.loc[:,'dob'], format = '%d-%m-%Y %I-%p')"
]
},
{
"cell_type": "code",
"execution_count": 66,
"id": "97b740a0",
"metadata": {},
"outputs": [],
"source": [
"df['dob'] = pd.to_datetime(df.loc[:,'dob'], format = '%d-%m-%Y %I-%p')"
]
},
{
"cell_type": "code",
"execution_count": 67,
"id": "585bdabc",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"name object\n",
"dob datetime64[ns]\n",
"address object\n",
"gender object\n",
"dtype: object"
]
},
"execution_count": 67,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df.dtypes"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "dcc94768",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "5474f1da",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "5e1c4bc5",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "f04dee48",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "d53767e3",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"id": "d62068ea",
"metadata": {},
"source": [
"### b. Option 2: Do the Conversion while Reading the CSV File"
]
},
{
"cell_type": "markdown",
"id": "b115624c",
"metadata": {},
"source": [
">**One can use the `parse_dates` and `date_parser` argument to the `pd.read_csv()` method to do this conversion while reading the csv file. However, the `pd.to_datetime()` method discussed above is recommended.**"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "e8e56359",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "a8c57490",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "b73bfd5c",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "f7d2e302",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "fea9323d",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"id": "085f8cc3",
"metadata": {},
"source": [
"## 5. Practicing with UFO Dataset\n",
"\n",
" "
]
},
{
"cell_type": "markdown",
"id": "97b21c71",
"metadata": {},
"source": [
"### a. Understanding the Dataset"
]
},
{
"cell_type": "code",
"execution_count": 68,
"id": "5f2c69fc",
"metadata": {
"scrolled": true
},
"outputs": [],
"source": [
"import pandas as pd\n",
"df = pd.read_csv(\"datasets/ufo.csv\")"
]
},
{
"cell_type": "code",
"execution_count": 69,
"id": "ecbb8eb6",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
"
\n",
" \n",
" \n",
" \n",
" City \n",
" Colors Reported \n",
" Shape Reported \n",
" State \n",
" Time \n",
" \n",
" \n",
" \n",
" \n",
" 0 \n",
" Ithaca \n",
" NaN \n",
" TRIANGLE \n",
" NY \n",
" 6/1/1930 22:00 \n",
" \n",
" \n",
" 1 \n",
" Willingboro \n",
" NaN \n",
" OTHER \n",
" NJ \n",
" 6/30/1930 20:00 \n",
" \n",
" \n",
" 2 \n",
" Holyoke \n",
" NaN \n",
" OVAL \n",
" CO \n",
" 2/15/1931 14:00 \n",
" \n",
" \n",
" 3 \n",
" Abilene \n",
" NaN \n",
" DISK \n",
" KS \n",
" 6/1/1931 13:00 \n",
" \n",
" \n",
" 4 \n",
" New York Worlds Fair \n",
" NaN \n",
" LIGHT \n",
" NY \n",
" 4/18/1933 19:00 \n",
" \n",
" \n",
" ... \n",
" ... \n",
" ... \n",
" ... \n",
" ... \n",
" ... \n",
" \n",
" \n",
" 18236 \n",
" Grant Park \n",
" NaN \n",
" TRIANGLE \n",
" IL \n",
" 12/31/2000 23:00 \n",
" \n",
" \n",
" 18237 \n",
" Spirit Lake \n",
" NaN \n",
" DISK \n",
" IA \n",
" 12/31/2000 23:00 \n",
" \n",
" \n",
" 18238 \n",
" Eagle River \n",
" NaN \n",
" NaN \n",
" WI \n",
" 12/31/2000 23:45 \n",
" \n",
" \n",
" 18239 \n",
" Eagle River \n",
" RED \n",
" LIGHT \n",
" WI \n",
" 12/31/2000 23:45 \n",
" \n",
" \n",
" 18240 \n",
" Ybor \n",
" NaN \n",
" OVAL \n",
" FL \n",
" 12/31/2000 23:59 \n",
" \n",
" \n",
"
\n",
"
18241 rows × 5 columns
\n",
"
"
],
"text/plain": [
" City Colors Reported Shape Reported State \\\n",
"0 Ithaca NaN TRIANGLE NY \n",
"1 Willingboro NaN OTHER NJ \n",
"2 Holyoke NaN OVAL CO \n",
"3 Abilene NaN DISK KS \n",
"4 New York Worlds Fair NaN LIGHT NY \n",
"... ... ... ... ... \n",
"18236 Grant Park NaN TRIANGLE IL \n",
"18237 Spirit Lake NaN DISK IA \n",
"18238 Eagle River NaN NaN WI \n",
"18239 Eagle River RED LIGHT WI \n",
"18240 Ybor NaN OVAL FL \n",
"\n",
" Time \n",
"0 6/1/1930 22:00 \n",
"1 6/30/1930 20:00 \n",
"2 2/15/1931 14:00 \n",
"3 6/1/1931 13:00 \n",
"4 4/18/1933 19:00 \n",
"... ... \n",
"18236 12/31/2000 23:00 \n",
"18237 12/31/2000 23:00 \n",
"18238 12/31/2000 23:45 \n",
"18239 12/31/2000 23:45 \n",
"18240 12/31/2000 23:59 \n",
"\n",
"[18241 rows x 5 columns]"
]
},
"execution_count": 69,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df"
]
},
{
"cell_type": "code",
"execution_count": 70,
"id": "5a3cdb51",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"City object\n",
"Colors Reported object\n",
"Shape Reported object\n",
"State object\n",
"Time object\n",
"dtype: object"
]
},
"execution_count": 70,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df.dtypes"
]
},
{
"cell_type": "code",
"execution_count": 71,
"id": "d3b02600",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\n",
"RangeIndex: 18241 entries, 0 to 18240\n",
"Data columns (total 5 columns):\n",
" # Column Non-Null Count Dtype \n",
"--- ------ -------------- ----- \n",
" 0 City 18216 non-null object\n",
" 1 Colors Reported 2882 non-null object\n",
" 2 Shape Reported 15597 non-null object\n",
" 3 State 18241 non-null object\n",
" 4 Time 18241 non-null object\n",
"dtypes: object(5)\n",
"memory usage: 712.7+ KB\n"
]
}
],
"source": [
"df.info()"
]
},
{
"cell_type": "code",
"execution_count": 72,
"id": "f6224595",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'6/1/1930 22:00'"
]
},
"execution_count": 72,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# The Time column of the dataframe contains strings\n",
"df.loc[0,'Time']"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "20bedc43",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "678a7106",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"id": "ef32cb7d",
"metadata": {},
"source": [
">Let us pass this column/series to the `pd.to_datetime()` method to convert the datatype to `datetime64`"
]
},
{
"cell_type": "code",
"execution_count": 73,
"id": "4897d804",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"0 1930-06-01 22:00:00\n",
"1 1930-06-30 20:00:00\n",
"2 1931-02-15 14:00:00\n",
"3 1931-06-01 13:00:00\n",
"4 1933-04-18 19:00:00\n",
" ... \n",
"18236 2000-12-31 23:00:00\n",
"18237 2000-12-31 23:00:00\n",
"18238 2000-12-31 23:45:00\n",
"18239 2000-12-31 23:45:00\n",
"18240 2000-12-31 23:59:00\n",
"Name: Time, Length: 18241, dtype: datetime64[ns]"
]
},
"execution_count": 73,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"pd.to_datetime(df.loc[:,'Time'])"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "0f950d96",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "1b2e0e90",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": 74,
"id": "33237b4a",
"metadata": {},
"outputs": [],
"source": [
"df['Time'] = pd.to_datetime(df.loc[:,'Time'])"
]
},
{
"cell_type": "code",
"execution_count": 75,
"id": "6182e264",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"City object\n",
"Colors Reported object\n",
"Shape Reported object\n",
"State object\n",
"Time datetime64[ns]\n",
"dtype: object"
]
},
"execution_count": 75,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df.dtypes"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "2a739d61",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "15cadce7",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "a180c728",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "68a438e3",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "47a167ee",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "da4053cd",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"id": "310f2108",
"metadata": {},
"source": [
"**Suppose I want to display only those UFO sightings that has been seen after 28 October 2000**"
]
},
{
"cell_type": "code",
"execution_count": 76,
"id": "81fd0bdd",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
"
\n",
" \n",
" \n",
" \n",
" City \n",
" Colors Reported \n",
" Shape Reported \n",
" State \n",
" Time \n",
" \n",
" \n",
" \n",
" \n",
" 17791 \n",
" Lake Worth \n",
" YELLOW \n",
" LIGHT \n",
" FL \n",
" 2000-10-28 00:00:00 \n",
" \n",
" \n",
" 17792 \n",
" Springfield \n",
" NaN \n",
" CIGAR \n",
" MO \n",
" 2000-10-28 00:00:00 \n",
" \n",
" \n",
" 17793 \n",
" Laurel \n",
" BLUE \n",
" SPHERE \n",
" MD \n",
" 2000-10-28 01:00:00 \n",
" \n",
" \n",
" 17794 \n",
" Portland \n",
" NaN \n",
" SPHERE \n",
" ME \n",
" 2000-10-28 10:30:00 \n",
" \n",
" \n",
" 17795 \n",
" Kintnersville \n",
" ORANGE \n",
" OTHER \n",
" PA \n",
" 2000-10-28 15:00:00 \n",
" \n",
" \n",
" ... \n",
" ... \n",
" ... \n",
" ... \n",
" ... \n",
" ... \n",
" \n",
" \n",
" 18236 \n",
" Grant Park \n",
" NaN \n",
" TRIANGLE \n",
" IL \n",
" 2000-12-31 23:00:00 \n",
" \n",
" \n",
" 18237 \n",
" Spirit Lake \n",
" NaN \n",
" DISK \n",
" IA \n",
" 2000-12-31 23:00:00 \n",
" \n",
" \n",
" 18238 \n",
" Eagle River \n",
" NaN \n",
" NaN \n",
" WI \n",
" 2000-12-31 23:45:00 \n",
" \n",
" \n",
" 18239 \n",
" Eagle River \n",
" RED \n",
" LIGHT \n",
" WI \n",
" 2000-12-31 23:45:00 \n",
" \n",
" \n",
" 18240 \n",
" Ybor \n",
" NaN \n",
" OVAL \n",
" FL \n",
" 2000-12-31 23:59:00 \n",
" \n",
" \n",
"
\n",
"
450 rows × 5 columns
\n",
"
"
],
"text/plain": [
" City Colors Reported Shape Reported State Time\n",
"17791 Lake Worth YELLOW LIGHT FL 2000-10-28 00:00:00\n",
"17792 Springfield NaN CIGAR MO 2000-10-28 00:00:00\n",
"17793 Laurel BLUE SPHERE MD 2000-10-28 01:00:00\n",
"17794 Portland NaN SPHERE ME 2000-10-28 10:30:00\n",
"17795 Kintnersville ORANGE OTHER PA 2000-10-28 15:00:00\n",
"... ... ... ... ... ...\n",
"18236 Grant Park NaN TRIANGLE IL 2000-12-31 23:00:00\n",
"18237 Spirit Lake NaN DISK IA 2000-12-31 23:00:00\n",
"18238 Eagle River NaN NaN WI 2000-12-31 23:45:00\n",
"18239 Eagle River RED LIGHT WI 2000-12-31 23:45:00\n",
"18240 Ybor NaN OVAL FL 2000-12-31 23:59:00\n",
"\n",
"[450 rows x 5 columns]"
]
},
"execution_count": 76,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Use Boolean Indexing (Can compare a string with datetime object)\n",
"df.loc[df.Time >= '2000/10/28', :]"
]
},
{
"cell_type": "code",
"execution_count": 77,
"id": "65f6b28a",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
"
\n",
" \n",
" \n",
" \n",
" City \n",
" Colors Reported \n",
" Shape Reported \n",
" State \n",
" Time \n",
" \n",
" \n",
" \n",
" \n",
" 17791 \n",
" Lake Worth \n",
" YELLOW \n",
" LIGHT \n",
" FL \n",
" 2000-10-28 00:00:00 \n",
" \n",
" \n",
" 17792 \n",
" Springfield \n",
" NaN \n",
" CIGAR \n",
" MO \n",
" 2000-10-28 00:00:00 \n",
" \n",
" \n",
" 17793 \n",
" Laurel \n",
" BLUE \n",
" SPHERE \n",
" MD \n",
" 2000-10-28 01:00:00 \n",
" \n",
" \n",
" 17794 \n",
" Portland \n",
" NaN \n",
" SPHERE \n",
" ME \n",
" 2000-10-28 10:30:00 \n",
" \n",
" \n",
" 17795 \n",
" Kintnersville \n",
" ORANGE \n",
" OTHER \n",
" PA \n",
" 2000-10-28 15:00:00 \n",
" \n",
" \n",
" ... \n",
" ... \n",
" ... \n",
" ... \n",
" ... \n",
" ... \n",
" \n",
" \n",
" 18236 \n",
" Grant Park \n",
" NaN \n",
" TRIANGLE \n",
" IL \n",
" 2000-12-31 23:00:00 \n",
" \n",
" \n",
" 18237 \n",
" Spirit Lake \n",
" NaN \n",
" DISK \n",
" IA \n",
" 2000-12-31 23:00:00 \n",
" \n",
" \n",
" 18238 \n",
" Eagle River \n",
" NaN \n",
" NaN \n",
" WI \n",
" 2000-12-31 23:45:00 \n",
" \n",
" \n",
" 18239 \n",
" Eagle River \n",
" RED \n",
" LIGHT \n",
" WI \n",
" 2000-12-31 23:45:00 \n",
" \n",
" \n",
" 18240 \n",
" Ybor \n",
" NaN \n",
" OVAL \n",
" FL \n",
" 2000-12-31 23:59:00 \n",
" \n",
" \n",
"
\n",
"
450 rows × 5 columns
\n",
"
"
],
"text/plain": [
" City Colors Reported Shape Reported State Time\n",
"17791 Lake Worth YELLOW LIGHT FL 2000-10-28 00:00:00\n",
"17792 Springfield NaN CIGAR MO 2000-10-28 00:00:00\n",
"17793 Laurel BLUE SPHERE MD 2000-10-28 01:00:00\n",
"17794 Portland NaN SPHERE ME 2000-10-28 10:30:00\n",
"17795 Kintnersville ORANGE OTHER PA 2000-10-28 15:00:00\n",
"... ... ... ... ... ...\n",
"18236 Grant Park NaN TRIANGLE IL 2000-12-31 23:00:00\n",
"18237 Spirit Lake NaN DISK IA 2000-12-31 23:00:00\n",
"18238 Eagle River NaN NaN WI 2000-12-31 23:45:00\n",
"18239 Eagle River RED LIGHT WI 2000-12-31 23:45:00\n",
"18240 Ybor NaN OVAL FL 2000-12-31 23:59:00\n",
"\n",
"[450 rows x 5 columns]"
]
},
"execution_count": 77,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Create a datetime object to be used for comparison\n",
"ts = pd.to_datetime('2000/10/28')\n",
"df.loc[df.Time >= ts, :]"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "0ccd9678",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "a42f88d4",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "b5be6ce3",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "ac59fab4",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "2148d072",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"id": "b112ce4e",
"metadata": {},
"source": [
"**Suppose I want to display only those UFO sightings that has been seen between 1st March 1995 and 06 March 1995**"
]
},
{
"cell_type": "code",
"execution_count": 78,
"id": "6033cd64",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
"
\n",
" \n",
" \n",
" \n",
" City \n",
" Colors Reported \n",
" Shape Reported \n",
" State \n",
" Time \n",
" \n",
" \n",
" \n",
" \n",
" 7860 \n",
" Greenville \n",
" NaN \n",
" LIGHT \n",
" IL \n",
" 1995-03-01 21:00:00 \n",
" \n",
" \n",
" 7861 \n",
" Sedalia \n",
" NaN \n",
" NaN \n",
" MO \n",
" 1995-03-01 21:00:00 \n",
" \n",
" \n",
" 7862 \n",
" Redmond \n",
" RED \n",
" NaN \n",
" WA \n",
" 1995-03-02 22:30:00 \n",
" \n",
" \n",
" 7863 \n",
" Prescott Valley \n",
" NaN \n",
" OVAL \n",
" AZ \n",
" 1995-03-04 00:00:00 \n",
" \n",
" \n",
" 7864 \n",
" Folsom \n",
" NaN \n",
" NaN \n",
" NJ \n",
" 1995-03-04 16:32:00 \n",
" \n",
" \n",
" 7865 \n",
" Anaheim \n",
" NaN \n",
" OTHER \n",
" CA \n",
" 1995-03-05 12:00:00 \n",
" \n",
" \n",
" 7866 \n",
" Columbus \n",
" NaN \n",
" NaN \n",
" OH \n",
" 1995-03-06 00:55:00 \n",
" \n",
" \n",
" 7867 \n",
" Hilltop \n",
" NaN \n",
" NaN \n",
" NJ \n",
" 1995-03-06 19:00:00 \n",
" \n",
" \n",
" 7868 \n",
" Florence \n",
" NaN \n",
" NaN \n",
" OR \n",
" 1995-03-06 19:10:00 \n",
" \n",
" \n",
" 7869 \n",
" Mountain City \n",
" NaN \n",
" NaN \n",
" TN \n",
" 1995-03-06 19:45:00 \n",
" \n",
" \n",
" 7870 \n",
" Ft. Bragg \n",
" NaN \n",
" NaN \n",
" CA \n",
" 1995-03-06 22:09:00 \n",
" \n",
" \n",
" 7871 \n",
" Burley \n",
" NaN \n",
" NaN \n",
" WA \n",
" 1995-03-06 23:30:00 \n",
" \n",
" \n",
"
\n",
"
"
],
"text/plain": [
" City Colors Reported Shape Reported State Time\n",
"7860 Greenville NaN LIGHT IL 1995-03-01 21:00:00\n",
"7861 Sedalia NaN NaN MO 1995-03-01 21:00:00\n",
"7862 Redmond RED NaN WA 1995-03-02 22:30:00\n",
"7863 Prescott Valley NaN OVAL AZ 1995-03-04 00:00:00\n",
"7864 Folsom NaN NaN NJ 1995-03-04 16:32:00\n",
"7865 Anaheim NaN OTHER CA 1995-03-05 12:00:00\n",
"7866 Columbus NaN NaN OH 1995-03-06 00:55:00\n",
"7867 Hilltop NaN NaN NJ 1995-03-06 19:00:00\n",
"7868 Florence NaN NaN OR 1995-03-06 19:10:00\n",
"7869 Mountain City NaN NaN TN 1995-03-06 19:45:00\n",
"7870 Ft. Bragg NaN NaN CA 1995-03-06 22:09:00\n",
"7871 Burley NaN NaN WA 1995-03-06 23:30:00"
]
},
"execution_count": 78,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Create a datetime object to be used for comparison\n",
"ts1 = pd.to_datetime('1995/03/1')\n",
"ts2 = pd.to_datetime('1995/03/7')\n",
"df.loc[(df.Time >= ts1) & (df.Time <= ts2), :]"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "dd24025f",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "4e86c876",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "42a058b2",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "2906dc80",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "d2f850cf",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "184cb99c",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"id": "3f0aaef6",
"metadata": {},
"source": [
"**Suppose I want to display the record of the maximum date under the `Time` column**"
]
},
{
"cell_type": "code",
"execution_count": 79,
"id": "2ce38867",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"Timestamp('2000-12-31 23:59:00')"
]
},
"execution_count": 79,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"ts = df.Time.max()\n",
"ts"
]
},
{
"cell_type": "code",
"execution_count": 80,
"id": "3d435c7e",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
"
\n",
" \n",
" \n",
" \n",
" City \n",
" Colors Reported \n",
" Shape Reported \n",
" State \n",
" Time \n",
" \n",
" \n",
" \n",
" \n",
" 18240 \n",
" Ybor \n",
" NaN \n",
" OVAL \n",
" FL \n",
" 2000-12-31 23:59:00 \n",
" \n",
" \n",
"
\n",
"
"
],
"text/plain": [
" City Colors Reported Shape Reported State Time\n",
"18240 Ybor NaN OVAL FL 2000-12-31 23:59:00"
]
},
"execution_count": 80,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df.loc[df.Time == ts]"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "93421bc1",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "27092f84",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "17bd18b3",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "a9b7efcb",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "5255c7a3",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "0c2d5aa5",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "0bb33fab",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"id": "48ffb7cc",
"metadata": {},
"source": [
"**Suppose I want to display the oldest record as per the `Time` column**"
]
},
{
"cell_type": "code",
"execution_count": 81,
"id": "73cbb2fa",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"Timestamp('1930-06-01 22:00:00')"
]
},
"execution_count": 81,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"ts = df.Time.min()\n",
"ts"
]
},
{
"cell_type": "code",
"execution_count": 82,
"id": "56600dc9",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
"
\n",
" \n",
" \n",
" \n",
" City \n",
" Colors Reported \n",
" Shape Reported \n",
" State \n",
" Time \n",
" \n",
" \n",
" \n",
" \n",
" 0 \n",
" Ithaca \n",
" NaN \n",
" TRIANGLE \n",
" NY \n",
" 1930-06-01 22:00:00 \n",
" \n",
" \n",
"
\n",
"
"
],
"text/plain": [
" City Colors Reported Shape Reported State Time\n",
"0 Ithaca NaN TRIANGLE NY 1930-06-01 22:00:00"
]
},
"execution_count": 82,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df.loc[df.Time == ts]"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "6f7a80d6",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "8662123d",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "6120814c",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "edb69f0d",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "d249c3a2",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "7ee305e2",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "8d38852a",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"id": "20179e67",
"metadata": {},
"source": [
"**Suppose I want to check out the difference between the oldest and the newest record as per the `Time` column**"
]
},
{
"cell_type": "code",
"execution_count": 83,
"id": "091952b7",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"25781 days 01:59:00\n",
"\n"
]
}
],
"source": [
"td = df.Time.max() - df.Time.min()\n",
"print(td)\n",
"print(type(td))"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "da0e5155",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "294ee562",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "2c1cf28e",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "847c20bb",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "7ad6930b",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "efe70970",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"id": "29739387",
"metadata": {},
"source": [
"## 6. Practicing with Crypto-Currency Dataset\n",
"\n",
" "
]
},
{
"cell_type": "code",
"execution_count": 84,
"id": "731aaae1",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
"
\n",
" \n",
" \n",
" \n",
" Date \n",
" Symbol \n",
" Open \n",
" High \n",
" Low \n",
" Close \n",
" Volume \n",
" \n",
" \n",
" \n",
" \n",
" 0 \n",
" 2020-03-13 08-PM \n",
" ETHUSD \n",
" 129.94 \n",
" 131.82 \n",
" 126.87 \n",
" 128.71 \n",
" 1940673.93 \n",
" \n",
" \n",
" 1 \n",
" 2020-03-13 07-PM \n",
" ETHUSD \n",
" 119.51 \n",
" 132.02 \n",
" 117.10 \n",
" 129.94 \n",
" 7579741.09 \n",
" \n",
" \n",
" 2 \n",
" 2020-03-13 06-PM \n",
" ETHUSD \n",
" 124.47 \n",
" 124.85 \n",
" 115.50 \n",
" 119.51 \n",
" 4898735.81 \n",
" \n",
" \n",
" 3 \n",
" 2020-03-13 05-PM \n",
" ETHUSD \n",
" 124.08 \n",
" 127.42 \n",
" 121.63 \n",
" 124.47 \n",
" 2753450.92 \n",
" \n",
" \n",
" 4 \n",
" 2020-03-13 04-PM \n",
" ETHUSD \n",
" 124.85 \n",
" 129.51 \n",
" 120.17 \n",
" 124.08 \n",
" 4461424.71 \n",
" \n",
" \n",
" ... \n",
" ... \n",
" ... \n",
" ... \n",
" ... \n",
" ... \n",
" ... \n",
" ... \n",
" \n",
" \n",
" 23669 \n",
" 2017-07-01 03-PM \n",
" ETHUSD \n",
" 265.74 \n",
" 272.74 \n",
" 265.00 \n",
" 272.57 \n",
" 1500282.55 \n",
" \n",
" \n",
" 23670 \n",
" 2017-07-01 02-PM \n",
" ETHUSD \n",
" 268.79 \n",
" 269.90 \n",
" 265.00 \n",
" 265.74 \n",
" 1702536.85 \n",
" \n",
" \n",
" 23671 \n",
" 2017-07-01 01-PM \n",
" ETHUSD \n",
" 274.83 \n",
" 274.93 \n",
" 265.00 \n",
" 268.79 \n",
" 3010787.99 \n",
" \n",
" \n",
" 23672 \n",
" 2017-07-01 12-PM \n",
" ETHUSD \n",
" 275.01 \n",
" 275.01 \n",
" 271.00 \n",
" 274.83 \n",
" 824362.87 \n",
" \n",
" \n",
" 23673 \n",
" 2017-07-01 11-AM \n",
" ETHUSD \n",
" 279.98 \n",
" 279.99 \n",
" 272.10 \n",
" 275.01 \n",
" 679358.87 \n",
" \n",
" \n",
"
\n",
"
23674 rows × 7 columns
\n",
"
"
],
"text/plain": [
" Date Symbol Open High Low Close Volume\n",
"0 2020-03-13 08-PM ETHUSD 129.94 131.82 126.87 128.71 1940673.93\n",
"1 2020-03-13 07-PM ETHUSD 119.51 132.02 117.10 129.94 7579741.09\n",
"2 2020-03-13 06-PM ETHUSD 124.47 124.85 115.50 119.51 4898735.81\n",
"3 2020-03-13 05-PM ETHUSD 124.08 127.42 121.63 124.47 2753450.92\n",
"4 2020-03-13 04-PM ETHUSD 124.85 129.51 120.17 124.08 4461424.71\n",
"... ... ... ... ... ... ... ...\n",
"23669 2017-07-01 03-PM ETHUSD 265.74 272.74 265.00 272.57 1500282.55\n",
"23670 2017-07-01 02-PM ETHUSD 268.79 269.90 265.00 265.74 1702536.85\n",
"23671 2017-07-01 01-PM ETHUSD 274.83 274.93 265.00 268.79 3010787.99\n",
"23672 2017-07-01 12-PM ETHUSD 275.01 275.01 271.00 274.83 824362.87\n",
"23673 2017-07-01 11-AM ETHUSD 279.98 279.99 272.10 275.01 679358.87\n",
"\n",
"[23674 rows x 7 columns]"
]
},
"execution_count": 84,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"import pandas as pd\n",
"df = pd.read_csv(\"datasets/cryptodata.csv\")\n",
"df"
]
},
{
"cell_type": "code",
"execution_count": 85,
"id": "35887ae8",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'2020-03-13 08-PM'"
]
},
"execution_count": 85,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# The Date column of the dataframe contains strings\n",
"df.loc[0,'Date']"
]
},
{
"cell_type": "code",
"execution_count": 86,
"id": "dc902395",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"Date object\n",
"Symbol object\n",
"Open float64\n",
"High float64\n",
"Low float64\n",
"Close float64\n",
"Volume float64\n",
"dtype: object"
]
},
"execution_count": 86,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df.dtypes"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "c7d0d861",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "767ccf3b",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "f86366ee",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"id": "6d6533d3",
"metadata": {},
"source": [
"### a. Convert the Datatype of Date Column to Datetime"
]
},
{
"cell_type": "markdown",
"id": "0cd4d030",
"metadata": {},
"source": [
">Let us pass this column/series to the `pd.to_datetime()` method to convert the datatype to `datetime64`"
]
},
{
"cell_type": "code",
"execution_count": 87,
"id": "dab7b0f0",
"metadata": {},
"outputs": [],
"source": [
"# ParserError: Unknown string format: 2020-03-13 08-PM\n",
"#pd.to_datetime(df.loc[:,'Date'])"
]
},
{
"cell_type": "code",
"execution_count": 88,
"id": "fcbdaefe",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"0 2020-03-13 20:00:00\n",
"1 2020-03-13 19:00:00\n",
"2 2020-03-13 18:00:00\n",
"3 2020-03-13 17:00:00\n",
"4 2020-03-13 16:00:00\n",
" ... \n",
"23669 2017-07-01 15:00:00\n",
"23670 2017-07-01 14:00:00\n",
"23671 2017-07-01 13:00:00\n",
"23672 2017-07-01 12:00:00\n",
"23673 2017-07-01 11:00:00\n",
"Name: Date, Length: 23674, dtype: datetime64[ns]"
]
},
"execution_count": 88,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"pd.to_datetime(df.loc[:,'Date'], format = '%Y-%m-%d %I-%p')"
]
},
{
"cell_type": "code",
"execution_count": 89,
"id": "6ce74259",
"metadata": {},
"outputs": [],
"source": [
"df['Date'] = pd.to_datetime(df.loc[:,'Date'], format = '%Y-%m-%d %I-%p')"
]
},
{
"cell_type": "code",
"execution_count": 90,
"id": "8718dbfc",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"Date datetime64[ns]\n",
"Symbol object\n",
"Open float64\n",
"High float64\n",
"Low float64\n",
"Close float64\n",
"Volume float64\n",
"dtype: object"
]
},
"execution_count": 90,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df.dtypes"
]
},
{
"cell_type": "code",
"execution_count": 91,
"id": "b8dcc21f",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"pandas._libs.tslibs.timestamps.Timestamp"
]
},
"execution_count": 91,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"type(df['Date'][0])"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "8237ba2a",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "1cda80a6",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "8af08294",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "32dbda15",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "8508aa8c",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "ad1482a1",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"id": "26ab381d",
"metadata": {},
"source": [
"**Let us create a new column in the dataframe that shows the day of week in each row**"
]
},
{
"cell_type": "code",
"execution_count": 92,
"id": "a12a943f",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"0 Friday\n",
"1 Friday\n",
"2 Friday\n",
"3 Friday\n",
"4 Friday\n",
" ... \n",
"23669 Saturday\n",
"23670 Saturday\n",
"23671 Saturday\n",
"23672 Saturday\n",
"23673 Saturday\n",
"Name: Date, Length: 23674, dtype: object"
]
},
"execution_count": 92,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df['Date'].dt.day_name()"
]
},
{
"cell_type": "code",
"execution_count": 93,
"id": "fa6c6e4e",
"metadata": {},
"outputs": [],
"source": [
"df['dayofweek'] = df['Date'].dt.day_name()"
]
},
{
"cell_type": "code",
"execution_count": 94,
"id": "38b86025",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
"
\n",
" \n",
" \n",
" \n",
" Date \n",
" Symbol \n",
" Open \n",
" High \n",
" Low \n",
" Close \n",
" Volume \n",
" dayofweek \n",
" \n",
" \n",
" \n",
" \n",
" 0 \n",
" 2020-03-13 20:00:00 \n",
" ETHUSD \n",
" 129.94 \n",
" 131.82 \n",
" 126.87 \n",
" 128.71 \n",
" 1940673.93 \n",
" Friday \n",
" \n",
" \n",
" 1 \n",
" 2020-03-13 19:00:00 \n",
" ETHUSD \n",
" 119.51 \n",
" 132.02 \n",
" 117.10 \n",
" 129.94 \n",
" 7579741.09 \n",
" Friday \n",
" \n",
" \n",
" 2 \n",
" 2020-03-13 18:00:00 \n",
" ETHUSD \n",
" 124.47 \n",
" 124.85 \n",
" 115.50 \n",
" 119.51 \n",
" 4898735.81 \n",
" Friday \n",
" \n",
" \n",
" 3 \n",
" 2020-03-13 17:00:00 \n",
" ETHUSD \n",
" 124.08 \n",
" 127.42 \n",
" 121.63 \n",
" 124.47 \n",
" 2753450.92 \n",
" Friday \n",
" \n",
" \n",
" 4 \n",
" 2020-03-13 16:00:00 \n",
" ETHUSD \n",
" 124.85 \n",
" 129.51 \n",
" 120.17 \n",
" 124.08 \n",
" 4461424.71 \n",
" Friday \n",
" \n",
" \n",
" ... \n",
" ... \n",
" ... \n",
" ... \n",
" ... \n",
" ... \n",
" ... \n",
" ... \n",
" ... \n",
" \n",
" \n",
" 23669 \n",
" 2017-07-01 15:00:00 \n",
" ETHUSD \n",
" 265.74 \n",
" 272.74 \n",
" 265.00 \n",
" 272.57 \n",
" 1500282.55 \n",
" Saturday \n",
" \n",
" \n",
" 23670 \n",
" 2017-07-01 14:00:00 \n",
" ETHUSD \n",
" 268.79 \n",
" 269.90 \n",
" 265.00 \n",
" 265.74 \n",
" 1702536.85 \n",
" Saturday \n",
" \n",
" \n",
" 23671 \n",
" 2017-07-01 13:00:00 \n",
" ETHUSD \n",
" 274.83 \n",
" 274.93 \n",
" 265.00 \n",
" 268.79 \n",
" 3010787.99 \n",
" Saturday \n",
" \n",
" \n",
" 23672 \n",
" 2017-07-01 12:00:00 \n",
" ETHUSD \n",
" 275.01 \n",
" 275.01 \n",
" 271.00 \n",
" 274.83 \n",
" 824362.87 \n",
" Saturday \n",
" \n",
" \n",
" 23673 \n",
" 2017-07-01 11:00:00 \n",
" ETHUSD \n",
" 279.98 \n",
" 279.99 \n",
" 272.10 \n",
" 275.01 \n",
" 679358.87 \n",
" Saturday \n",
" \n",
" \n",
"
\n",
"
23674 rows × 8 columns
\n",
"
"
],
"text/plain": [
" Date Symbol Open High Low Close Volume \\\n",
"0 2020-03-13 20:00:00 ETHUSD 129.94 131.82 126.87 128.71 1940673.93 \n",
"1 2020-03-13 19:00:00 ETHUSD 119.51 132.02 117.10 129.94 7579741.09 \n",
"2 2020-03-13 18:00:00 ETHUSD 124.47 124.85 115.50 119.51 4898735.81 \n",
"3 2020-03-13 17:00:00 ETHUSD 124.08 127.42 121.63 124.47 2753450.92 \n",
"4 2020-03-13 16:00:00 ETHUSD 124.85 129.51 120.17 124.08 4461424.71 \n",
"... ... ... ... ... ... ... ... \n",
"23669 2017-07-01 15:00:00 ETHUSD 265.74 272.74 265.00 272.57 1500282.55 \n",
"23670 2017-07-01 14:00:00 ETHUSD 268.79 269.90 265.00 265.74 1702536.85 \n",
"23671 2017-07-01 13:00:00 ETHUSD 274.83 274.93 265.00 268.79 3010787.99 \n",
"23672 2017-07-01 12:00:00 ETHUSD 275.01 275.01 271.00 274.83 824362.87 \n",
"23673 2017-07-01 11:00:00 ETHUSD 279.98 279.99 272.10 275.01 679358.87 \n",
"\n",
" dayofweek \n",
"0 Friday \n",
"1 Friday \n",
"2 Friday \n",
"3 Friday \n",
"4 Friday \n",
"... ... \n",
"23669 Saturday \n",
"23670 Saturday \n",
"23671 Saturday \n",
"23672 Saturday \n",
"23673 Saturday \n",
"\n",
"[23674 rows x 8 columns]"
]
},
"execution_count": 94,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "c0e23bd3",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "58ae33bf",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "7e141fd2",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "7acd5577",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "af07cbbb",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"id": "e8d40883",
"metadata": {},
"source": [
"**Let us find the oldest and newest record in the dataframe**"
]
},
{
"cell_type": "code",
"execution_count": 95,
"id": "5ccf5dd2",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"Timestamp('2017-07-01 11:00:00')"
]
},
"execution_count": 95,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df['Date'].min()"
]
},
{
"cell_type": "code",
"execution_count": 96,
"id": "6963dfc6",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"Timestamp('2020-03-13 20:00:00')"
]
},
"execution_count": 96,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df['Date'].max()"
]
},
{
"cell_type": "code",
"execution_count": 97,
"id": "c9d27847",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"Timedelta('986 days 09:00:00')"
]
},
"execution_count": 97,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df['Date'].max() - df['Date'].min()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "f11357f8",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "714d4c15",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "a7c6ce91",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "dab9176e",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "d06f814c",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "5a77c0e6",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"id": "e98605ba",
"metadata": {},
"source": [
"**Let us find the records of the January 2020 only**"
]
},
{
"cell_type": "code",
"execution_count": 98,
"id": "b88f5c82",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"0 False\n",
"1 False\n",
"2 False\n",
"3 False\n",
"4 False\n",
" ... \n",
"23669 False\n",
"23670 False\n",
"23671 False\n",
"23672 False\n",
"23673 False\n",
"Name: Date, Length: 23674, dtype: bool"
]
},
"execution_count": 98,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"mask = (df['Date'] >= '2020-01-01') & (df['Date'] <= '2020-01-31')\n",
"mask"
]
},
{
"cell_type": "code",
"execution_count": 99,
"id": "f0259322",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
"
\n",
" \n",
" \n",
" \n",
" Date \n",
" Symbol \n",
" Open \n",
" High \n",
" Low \n",
" Close \n",
" Volume \n",
" dayofweek \n",
" \n",
" \n",
" \n",
" \n",
" 1028 \n",
" 2020-01-31 00:00:00 \n",
" ETHUSD \n",
" 184.55 \n",
" 185.68 \n",
" 183.48 \n",
" 183.82 \n",
" 1107068.24 \n",
" Friday \n",
" \n",
" \n",
" 1029 \n",
" 2020-01-30 23:00:00 \n",
" ETHUSD \n",
" 186.62 \n",
" 186.89 \n",
" 182.99 \n",
" 184.55 \n",
" 1262371.00 \n",
" Thursday \n",
" \n",
" \n",
" 1030 \n",
" 2020-01-30 22:00:00 \n",
" ETHUSD \n",
" 185.03 \n",
" 186.63 \n",
" 183.90 \n",
" 186.62 \n",
" 992325.34 \n",
" Thursday \n",
" \n",
" \n",
" 1031 \n",
" 2020-01-30 21:00:00 \n",
" ETHUSD \n",
" 184.40 \n",
" 185.03 \n",
" 183.19 \n",
" 185.03 \n",
" 701167.77 \n",
" Thursday \n",
" \n",
" \n",
" 1032 \n",
" 2020-01-30 20:00:00 \n",
" ETHUSD \n",
" 181.26 \n",
" 185.14 \n",
" 181.26 \n",
" 184.40 \n",
" 2180199.04 \n",
" Thursday \n",
" \n",
" \n",
" ... \n",
" ... \n",
" ... \n",
" ... \n",
" ... \n",
" ... \n",
" ... \n",
" ... \n",
" ... \n",
" \n",
" \n",
" 1744 \n",
" 2020-01-01 04:00:00 \n",
" ETHUSD \n",
" 129.57 \n",
" 130.00 \n",
" 129.50 \n",
" 129.56 \n",
" 702786.82 \n",
" Wednesday \n",
" \n",
" \n",
" 1745 \n",
" 2020-01-01 03:00:00 \n",
" ETHUSD \n",
" 130.37 \n",
" 130.44 \n",
" 129.38 \n",
" 129.57 \n",
" 496704.23 \n",
" Wednesday \n",
" \n",
" \n",
" 1746 \n",
" 2020-01-01 02:00:00 \n",
" ETHUSD \n",
" 130.14 \n",
" 130.50 \n",
" 129.91 \n",
" 130.37 \n",
" 396315.72 \n",
" Wednesday \n",
" \n",
" \n",
" 1747 \n",
" 2020-01-01 01:00:00 \n",
" ETHUSD \n",
" 128.34 \n",
" 130.14 \n",
" 128.32 \n",
" 130.14 \n",
" 635419.40 \n",
" Wednesday \n",
" \n",
" \n",
" 1748 \n",
" 2020-01-01 00:00:00 \n",
" ETHUSD \n",
" 128.54 \n",
" 128.54 \n",
" 128.12 \n",
" 128.34 \n",
" 245119.91 \n",
" Wednesday \n",
" \n",
" \n",
"
\n",
"
721 rows × 8 columns
\n",
"
"
],
"text/plain": [
" Date Symbol Open High Low Close Volume \\\n",
"1028 2020-01-31 00:00:00 ETHUSD 184.55 185.68 183.48 183.82 1107068.24 \n",
"1029 2020-01-30 23:00:00 ETHUSD 186.62 186.89 182.99 184.55 1262371.00 \n",
"1030 2020-01-30 22:00:00 ETHUSD 185.03 186.63 183.90 186.62 992325.34 \n",
"1031 2020-01-30 21:00:00 ETHUSD 184.40 185.03 183.19 185.03 701167.77 \n",
"1032 2020-01-30 20:00:00 ETHUSD 181.26 185.14 181.26 184.40 2180199.04 \n",
"... ... ... ... ... ... ... ... \n",
"1744 2020-01-01 04:00:00 ETHUSD 129.57 130.00 129.50 129.56 702786.82 \n",
"1745 2020-01-01 03:00:00 ETHUSD 130.37 130.44 129.38 129.57 496704.23 \n",
"1746 2020-01-01 02:00:00 ETHUSD 130.14 130.50 129.91 130.37 396315.72 \n",
"1747 2020-01-01 01:00:00 ETHUSD 128.34 130.14 128.32 130.14 635419.40 \n",
"1748 2020-01-01 00:00:00 ETHUSD 128.54 128.54 128.12 128.34 245119.91 \n",
"\n",
" dayofweek \n",
"1028 Friday \n",
"1029 Thursday \n",
"1030 Thursday \n",
"1031 Thursday \n",
"1032 Thursday \n",
"... ... \n",
"1744 Wednesday \n",
"1745 Wednesday \n",
"1746 Wednesday \n",
"1747 Wednesday \n",
"1748 Wednesday \n",
"\n",
"[721 rows x 8 columns]"
]
},
"execution_count": 99,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df.loc[mask]"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "f05a2861",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "2e03ca6c",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "86933cbd",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "f21cbaf3",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "e150ba05",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "c20d1037",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"id": "ca47752a",
"metadata": {},
"source": [
"### b. Set the Column `Date` as Row Index of Dataframe\n",
"- This will allow you to treat the entire dataset in the dataframe as a Time Series Data\n",
" - Selecting/Indexing using strings\n",
" - Slicing using `df[date1:date2]`\n",
" - Use of `df.loc[date1:date2, :]`"
]
},
{
"cell_type": "code",
"execution_count": 100,
"id": "5aaad6b6",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
"
\n",
" \n",
" \n",
" \n",
" Symbol \n",
" Open \n",
" High \n",
" Low \n",
" Close \n",
" Volume \n",
" dayofweek \n",
" \n",
" \n",
" Date \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" 2020-03-13 20:00:00 \n",
" ETHUSD \n",
" 129.94 \n",
" 131.82 \n",
" 126.87 \n",
" 128.71 \n",
" 1940673.93 \n",
" Friday \n",
" \n",
" \n",
" 2020-03-13 19:00:00 \n",
" ETHUSD \n",
" 119.51 \n",
" 132.02 \n",
" 117.10 \n",
" 129.94 \n",
" 7579741.09 \n",
" Friday \n",
" \n",
" \n",
" 2020-03-13 18:00:00 \n",
" ETHUSD \n",
" 124.47 \n",
" 124.85 \n",
" 115.50 \n",
" 119.51 \n",
" 4898735.81 \n",
" Friday \n",
" \n",
" \n",
" 2020-03-13 17:00:00 \n",
" ETHUSD \n",
" 124.08 \n",
" 127.42 \n",
" 121.63 \n",
" 124.47 \n",
" 2753450.92 \n",
" Friday \n",
" \n",
" \n",
" 2020-03-13 16:00:00 \n",
" ETHUSD \n",
" 124.85 \n",
" 129.51 \n",
" 120.17 \n",
" 124.08 \n",
" 4461424.71 \n",
" Friday \n",
" \n",
" \n",
" ... \n",
" ... \n",
" ... \n",
" ... \n",
" ... \n",
" ... \n",
" ... \n",
" ... \n",
" \n",
" \n",
" 2017-07-01 15:00:00 \n",
" ETHUSD \n",
" 265.74 \n",
" 272.74 \n",
" 265.00 \n",
" 272.57 \n",
" 1500282.55 \n",
" Saturday \n",
" \n",
" \n",
" 2017-07-01 14:00:00 \n",
" ETHUSD \n",
" 268.79 \n",
" 269.90 \n",
" 265.00 \n",
" 265.74 \n",
" 1702536.85 \n",
" Saturday \n",
" \n",
" \n",
" 2017-07-01 13:00:00 \n",
" ETHUSD \n",
" 274.83 \n",
" 274.93 \n",
" 265.00 \n",
" 268.79 \n",
" 3010787.99 \n",
" Saturday \n",
" \n",
" \n",
" 2017-07-01 12:00:00 \n",
" ETHUSD \n",
" 275.01 \n",
" 275.01 \n",
" 271.00 \n",
" 274.83 \n",
" 824362.87 \n",
" Saturday \n",
" \n",
" \n",
" 2017-07-01 11:00:00 \n",
" ETHUSD \n",
" 279.98 \n",
" 279.99 \n",
" 272.10 \n",
" 275.01 \n",
" 679358.87 \n",
" Saturday \n",
" \n",
" \n",
"
\n",
"
23674 rows × 7 columns
\n",
"
"
],
"text/plain": [
" Symbol Open High Low Close Volume \\\n",
"Date \n",
"2020-03-13 20:00:00 ETHUSD 129.94 131.82 126.87 128.71 1940673.93 \n",
"2020-03-13 19:00:00 ETHUSD 119.51 132.02 117.10 129.94 7579741.09 \n",
"2020-03-13 18:00:00 ETHUSD 124.47 124.85 115.50 119.51 4898735.81 \n",
"2020-03-13 17:00:00 ETHUSD 124.08 127.42 121.63 124.47 2753450.92 \n",
"2020-03-13 16:00:00 ETHUSD 124.85 129.51 120.17 124.08 4461424.71 \n",
"... ... ... ... ... ... ... \n",
"2017-07-01 15:00:00 ETHUSD 265.74 272.74 265.00 272.57 1500282.55 \n",
"2017-07-01 14:00:00 ETHUSD 268.79 269.90 265.00 265.74 1702536.85 \n",
"2017-07-01 13:00:00 ETHUSD 274.83 274.93 265.00 268.79 3010787.99 \n",
"2017-07-01 12:00:00 ETHUSD 275.01 275.01 271.00 274.83 824362.87 \n",
"2017-07-01 11:00:00 ETHUSD 279.98 279.99 272.10 275.01 679358.87 \n",
"\n",
" dayofweek \n",
"Date \n",
"2020-03-13 20:00:00 Friday \n",
"2020-03-13 19:00:00 Friday \n",
"2020-03-13 18:00:00 Friday \n",
"2020-03-13 17:00:00 Friday \n",
"2020-03-13 16:00:00 Friday \n",
"... ... \n",
"2017-07-01 15:00:00 Saturday \n",
"2017-07-01 14:00:00 Saturday \n",
"2017-07-01 13:00:00 Saturday \n",
"2017-07-01 12:00:00 Saturday \n",
"2017-07-01 11:00:00 Saturday \n",
"\n",
"[23674 rows x 7 columns]"
]
},
"execution_count": 100,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df.set_index('Date', inplace=True)\n",
"df"
]
},
{
"cell_type": "markdown",
"id": "35509834",
"metadata": {},
"source": [
">Now, since the data of the `Date` column has become the row indices of this dataframe, therefore, we can use `.loc[]` on the dates :)\n",
"- Since index is still unique so the searching will be done in O(1) time\n",
"- If non-unique but sorted the searching will take O(logn) time\n",
"- If non-unique and non-sorted the searching will take O(n) time"
]
},
{
"cell_type": "markdown",
"id": "92658fc6",
"metadata": {},
"source": [
"**(i) Selection:**"
]
},
{
"cell_type": "code",
"execution_count": 101,
"id": "3bb995ed",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
"
\n",
" \n",
" \n",
" \n",
" Symbol \n",
" Open \n",
" High \n",
" Low \n",
" Close \n",
" Volume \n",
" dayofweek \n",
" \n",
" \n",
" Date \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" 2019-07-01 23:00:00 \n",
" ETHUSD \n",
" 289.24 \n",
" 295.93 \n",
" 289.24 \n",
" 293.70 \n",
" 2083299.02 \n",
" Monday \n",
" \n",
" \n",
" 2019-07-01 22:00:00 \n",
" ETHUSD \n",
" 291.17 \n",
" 291.31 \n",
" 288.10 \n",
" 289.24 \n",
" 1865830.49 \n",
" Monday \n",
" \n",
" \n",
" 2019-07-01 21:00:00 \n",
" ETHUSD \n",
" 288.82 \n",
" 292.61 \n",
" 288.82 \n",
" 291.17 \n",
" 1731914.78 \n",
" Monday \n",
" \n",
" \n",
" 2019-07-01 20:00:00 \n",
" ETHUSD \n",
" 281.38 \n",
" 290.94 \n",
" 281.38 \n",
" 288.82 \n",
" 3483143.68 \n",
" Monday \n",
" \n",
" \n",
" 2019-07-01 19:00:00 \n",
" ETHUSD \n",
" 284.73 \n",
" 284.97 \n",
" 278.75 \n",
" 281.38 \n",
" 3420031.90 \n",
" Monday \n",
" \n",
" \n",
" 2019-07-01 18:00:00 \n",
" ETHUSD \n",
" 282.89 \n",
" 285.76 \n",
" 281.50 \n",
" 284.73 \n",
" 1841330.22 \n",
" Monday \n",
" \n",
" \n",
" 2019-07-01 17:00:00 \n",
" ETHUSD \n",
" 283.39 \n",
" 285.39 \n",
" 280.51 \n",
" 282.89 \n",
" 2346140.58 \n",
" Monday \n",
" \n",
" \n",
" 2019-07-01 16:00:00 \n",
" ETHUSD \n",
" 284.49 \n",
" 287.48 \n",
" 282.01 \n",
" 283.39 \n",
" 3244834.65 \n",
" Monday \n",
" \n",
" \n",
" 2019-07-01 15:00:00 \n",
" ETHUSD \n",
" 280.76 \n",
" 286.74 \n",
" 278.65 \n",
" 284.49 \n",
" 6552331.53 \n",
" Monday \n",
" \n",
" \n",
" 2019-07-01 14:00:00 \n",
" ETHUSD \n",
" 285.50 \n",
" 289.37 \n",
" 280.15 \n",
" 280.76 \n",
" 3386287.24 \n",
" Monday \n",
" \n",
" \n",
" 2019-07-01 13:00:00 \n",
" ETHUSD \n",
" 288.79 \n",
" 289.98 \n",
" 285.50 \n",
" 285.50 \n",
" 2447312.95 \n",
" Monday \n",
" \n",
" \n",
" 2019-07-01 12:00:00 \n",
" ETHUSD \n",
" 294.27 \n",
" 295.62 \n",
" 284.16 \n",
" 288.79 \n",
" 2967508.75 \n",
" Monday \n",
" \n",
" \n",
" 2019-07-01 11:00:00 \n",
" ETHUSD \n",
" 294.18 \n",
" 294.83 \n",
" 292.23 \n",
" 294.27 \n",
" 697966.32 \n",
" Monday \n",
" \n",
" \n",
" 2019-07-01 10:00:00 \n",
" ETHUSD \n",
" 296.52 \n",
" 297.50 \n",
" 292.07 \n",
" 294.18 \n",
" 1267176.41 \n",
" Monday \n",
" \n",
" \n",
" 2019-07-01 09:00:00 \n",
" ETHUSD \n",
" 298.10 \n",
" 298.24 \n",
" 296.01 \n",
" 296.52 \n",
" 499072.13 \n",
" Monday \n",
" \n",
" \n",
" 2019-07-01 08:00:00 \n",
" ETHUSD \n",
" 293.05 \n",
" 298.10 \n",
" 292.92 \n",
" 298.10 \n",
" 1192722.45 \n",
" Monday \n",
" \n",
" \n",
" 2019-07-01 07:00:00 \n",
" ETHUSD \n",
" 292.90 \n",
" 296.01 \n",
" 290.48 \n",
" 293.05 \n",
" 1483583.90 \n",
" Monday \n",
" \n",
" \n",
" 2019-07-01 06:00:00 \n",
" ETHUSD \n",
" 294.56 \n",
" 295.92 \n",
" 291.73 \n",
" 292.90 \n",
" 1068694.39 \n",
" Monday \n",
" \n",
" \n",
" 2019-07-01 05:00:00 \n",
" ETHUSD \n",
" 297.97 \n",
" 298.24 \n",
" 293.95 \n",
" 294.56 \n",
" 1277630.93 \n",
" Monday \n",
" \n",
" \n",
" 2019-07-01 04:00:00 \n",
" ETHUSD \n",
" 298.15 \n",
" 299.80 \n",
" 295.57 \n",
" 297.97 \n",
" 1036527.82 \n",
" Monday \n",
" \n",
" \n",
" 2019-07-01 03:00:00 \n",
" ETHUSD \n",
" 296.99 \n",
" 301.32 \n",
" 295.81 \n",
" 298.15 \n",
" 1465814.16 \n",
" Monday \n",
" \n",
" \n",
" 2019-07-01 02:00:00 \n",
" ETHUSD \n",
" 293.93 \n",
" 298.58 \n",
" 292.15 \n",
" 296.99 \n",
" 1367256.41 \n",
" Monday \n",
" \n",
" \n",
" 2019-07-01 01:00:00 \n",
" ETHUSD \n",
" 295.11 \n",
" 298.70 \n",
" 293.53 \n",
" 293.93 \n",
" 2293925.50 \n",
" Monday \n",
" \n",
" \n",
" 2019-07-01 00:00:00 \n",
" ETHUSD \n",
" 290.07 \n",
" 295.25 \n",
" 286.69 \n",
" 295.11 \n",
" 4209855.92 \n",
" Monday \n",
" \n",
" \n",
"
\n",
"
"
],
"text/plain": [
" Symbol Open High Low Close Volume \\\n",
"Date \n",
"2019-07-01 23:00:00 ETHUSD 289.24 295.93 289.24 293.70 2083299.02 \n",
"2019-07-01 22:00:00 ETHUSD 291.17 291.31 288.10 289.24 1865830.49 \n",
"2019-07-01 21:00:00 ETHUSD 288.82 292.61 288.82 291.17 1731914.78 \n",
"2019-07-01 20:00:00 ETHUSD 281.38 290.94 281.38 288.82 3483143.68 \n",
"2019-07-01 19:00:00 ETHUSD 284.73 284.97 278.75 281.38 3420031.90 \n",
"2019-07-01 18:00:00 ETHUSD 282.89 285.76 281.50 284.73 1841330.22 \n",
"2019-07-01 17:00:00 ETHUSD 283.39 285.39 280.51 282.89 2346140.58 \n",
"2019-07-01 16:00:00 ETHUSD 284.49 287.48 282.01 283.39 3244834.65 \n",
"2019-07-01 15:00:00 ETHUSD 280.76 286.74 278.65 284.49 6552331.53 \n",
"2019-07-01 14:00:00 ETHUSD 285.50 289.37 280.15 280.76 3386287.24 \n",
"2019-07-01 13:00:00 ETHUSD 288.79 289.98 285.50 285.50 2447312.95 \n",
"2019-07-01 12:00:00 ETHUSD 294.27 295.62 284.16 288.79 2967508.75 \n",
"2019-07-01 11:00:00 ETHUSD 294.18 294.83 292.23 294.27 697966.32 \n",
"2019-07-01 10:00:00 ETHUSD 296.52 297.50 292.07 294.18 1267176.41 \n",
"2019-07-01 09:00:00 ETHUSD 298.10 298.24 296.01 296.52 499072.13 \n",
"2019-07-01 08:00:00 ETHUSD 293.05 298.10 292.92 298.10 1192722.45 \n",
"2019-07-01 07:00:00 ETHUSD 292.90 296.01 290.48 293.05 1483583.90 \n",
"2019-07-01 06:00:00 ETHUSD 294.56 295.92 291.73 292.90 1068694.39 \n",
"2019-07-01 05:00:00 ETHUSD 297.97 298.24 293.95 294.56 1277630.93 \n",
"2019-07-01 04:00:00 ETHUSD 298.15 299.80 295.57 297.97 1036527.82 \n",
"2019-07-01 03:00:00 ETHUSD 296.99 301.32 295.81 298.15 1465814.16 \n",
"2019-07-01 02:00:00 ETHUSD 293.93 298.58 292.15 296.99 1367256.41 \n",
"2019-07-01 01:00:00 ETHUSD 295.11 298.70 293.53 293.93 2293925.50 \n",
"2019-07-01 00:00:00 ETHUSD 290.07 295.25 286.69 295.11 4209855.92 \n",
"\n",
" dayofweek \n",
"Date \n",
"2019-07-01 23:00:00 Monday \n",
"2019-07-01 22:00:00 Monday \n",
"2019-07-01 21:00:00 Monday \n",
"2019-07-01 20:00:00 Monday \n",
"2019-07-01 19:00:00 Monday \n",
"2019-07-01 18:00:00 Monday \n",
"2019-07-01 17:00:00 Monday \n",
"2019-07-01 16:00:00 Monday \n",
"2019-07-01 15:00:00 Monday \n",
"2019-07-01 14:00:00 Monday \n",
"2019-07-01 13:00:00 Monday \n",
"2019-07-01 12:00:00 Monday \n",
"2019-07-01 11:00:00 Monday \n",
"2019-07-01 10:00:00 Monday \n",
"2019-07-01 09:00:00 Monday \n",
"2019-07-01 08:00:00 Monday \n",
"2019-07-01 07:00:00 Monday \n",
"2019-07-01 06:00:00 Monday \n",
"2019-07-01 05:00:00 Monday \n",
"2019-07-01 04:00:00 Monday \n",
"2019-07-01 03:00:00 Monday \n",
"2019-07-01 02:00:00 Monday \n",
"2019-07-01 01:00:00 Monday \n",
"2019-07-01 00:00:00 Monday "
]
},
"execution_count": 101,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# retrieve data of july 2019\n",
"df.loc[\"2019-07-01\"]"
]
},
{
"cell_type": "code",
"execution_count": 102,
"id": "2c9be5ff",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"Date\n",
"2019-07-31 23:00:00 1066895.02\n",
"2019-07-31 22:00:00 328984.44\n",
"2019-07-31 21:00:00 492811.09\n",
"2019-07-31 20:00:00 391730.91\n",
"2019-07-31 19:00:00 417465.58\n",
" ... \n",
"2019-07-01 04:00:00 1036527.82\n",
"2019-07-01 03:00:00 1465814.16\n",
"2019-07-01 02:00:00 1367256.41\n",
"2019-07-01 01:00:00 2293925.50\n",
"2019-07-01 00:00:00 4209855.92\n",
"Name: Volume, Length: 744, dtype: float64"
]
},
"execution_count": 102,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# getting Volume of July 2019\n",
"df.loc[\"2019-07\"].Volume"
]
},
{
"cell_type": "code",
"execution_count": 103,
"id": "eb1c8412",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"1482188.5834811835"
]
},
"execution_count": 103,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Volumn average in July 2021\n",
"df.loc[\"2019-07\"].Volume.mean()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "a234fc32",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "a642e1c4",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "b6087bfa",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "6108648f",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"id": "54ce57f1",
"metadata": {},
"source": [
"**(ii) Slicing:**"
]
},
{
"cell_type": "code",
"execution_count": 104,
"id": "804a93a9",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
"
\n",
" \n",
" \n",
" \n",
" Symbol \n",
" Open \n",
" High \n",
" Low \n",
" Close \n",
" Volume \n",
" dayofweek \n",
" \n",
" \n",
" Date \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" 2020-02-29 23:00:00 \n",
" ETHUSD \n",
" 223.35 \n",
" 223.58 \n",
" 216.83 \n",
" 217.31 \n",
" 1927939.88 \n",
" Saturday \n",
" \n",
" \n",
" 2020-02-29 22:00:00 \n",
" ETHUSD \n",
" 223.48 \n",
" 223.59 \n",
" 222.14 \n",
" 223.35 \n",
" 535998.57 \n",
" Saturday \n",
" \n",
" \n",
" 2020-02-29 21:00:00 \n",
" ETHUSD \n",
" 224.63 \n",
" 225.14 \n",
" 222.74 \n",
" 223.48 \n",
" 561158.03 \n",
" Saturday \n",
" \n",
" \n",
" 2020-02-29 20:00:00 \n",
" ETHUSD \n",
" 225.31 \n",
" 225.33 \n",
" 223.50 \n",
" 224.63 \n",
" 511648.65 \n",
" Saturday \n",
" \n",
" \n",
" 2020-02-29 19:00:00 \n",
" ETHUSD \n",
" 225.09 \n",
" 225.85 \n",
" 223.87 \n",
" 225.31 \n",
" 1250856.20 \n",
" Saturday \n",
" \n",
" \n",
" ... \n",
" ... \n",
" ... \n",
" ... \n",
" ... \n",
" ... \n",
" ... \n",
" ... \n",
" \n",
" \n",
" 2020-01-01 04:00:00 \n",
" ETHUSD \n",
" 129.57 \n",
" 130.00 \n",
" 129.50 \n",
" 129.56 \n",
" 702786.82 \n",
" Wednesday \n",
" \n",
" \n",
" 2020-01-01 03:00:00 \n",
" ETHUSD \n",
" 130.37 \n",
" 130.44 \n",
" 129.38 \n",
" 129.57 \n",
" 496704.23 \n",
" Wednesday \n",
" \n",
" \n",
" 2020-01-01 02:00:00 \n",
" ETHUSD \n",
" 130.14 \n",
" 130.50 \n",
" 129.91 \n",
" 130.37 \n",
" 396315.72 \n",
" Wednesday \n",
" \n",
" \n",
" 2020-01-01 01:00:00 \n",
" ETHUSD \n",
" 128.34 \n",
" 130.14 \n",
" 128.32 \n",
" 130.14 \n",
" 635419.40 \n",
" Wednesday \n",
" \n",
" \n",
" 2020-01-01 00:00:00 \n",
" ETHUSD \n",
" 128.54 \n",
" 128.54 \n",
" 128.12 \n",
" 128.34 \n",
" 245119.91 \n",
" Wednesday \n",
" \n",
" \n",
"
\n",
"
1440 rows × 7 columns
\n",
"
"
],
"text/plain": [
" Symbol Open High Low Close Volume \\\n",
"Date \n",
"2020-02-29 23:00:00 ETHUSD 223.35 223.58 216.83 217.31 1927939.88 \n",
"2020-02-29 22:00:00 ETHUSD 223.48 223.59 222.14 223.35 535998.57 \n",
"2020-02-29 21:00:00 ETHUSD 224.63 225.14 222.74 223.48 561158.03 \n",
"2020-02-29 20:00:00 ETHUSD 225.31 225.33 223.50 224.63 511648.65 \n",
"2020-02-29 19:00:00 ETHUSD 225.09 225.85 223.87 225.31 1250856.20 \n",
"... ... ... ... ... ... ... \n",
"2020-01-01 04:00:00 ETHUSD 129.57 130.00 129.50 129.56 702786.82 \n",
"2020-01-01 03:00:00 ETHUSD 130.37 130.44 129.38 129.57 496704.23 \n",
"2020-01-01 02:00:00 ETHUSD 130.14 130.50 129.91 130.37 396315.72 \n",
"2020-01-01 01:00:00 ETHUSD 128.34 130.14 128.32 130.14 635419.40 \n",
"2020-01-01 00:00:00 ETHUSD 128.54 128.54 128.12 128.34 245119.91 \n",
"\n",
" dayofweek \n",
"Date \n",
"2020-02-29 23:00:00 Saturday \n",
"2020-02-29 22:00:00 Saturday \n",
"2020-02-29 21:00:00 Saturday \n",
"2020-02-29 20:00:00 Saturday \n",
"2020-02-29 19:00:00 Saturday \n",
"... ... \n",
"2020-01-01 04:00:00 Wednesday \n",
"2020-01-01 03:00:00 Wednesday \n",
"2020-01-01 02:00:00 Wednesday \n",
"2020-01-01 01:00:00 Wednesday \n",
"2020-01-01 00:00:00 Wednesday \n",
"\n",
"[1440 rows x 7 columns]"
]
},
"execution_count": 104,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Slice data of January and February 2020\n",
"df.loc['2020-01':'2020-02', :]"
]
},
{
"cell_type": "code",
"execution_count": 105,
"id": "676294e6",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"Date\n",
"2020-02-29 23:00:00 217.31\n",
"2020-02-29 22:00:00 223.35\n",
"2020-02-29 21:00:00 223.48\n",
"2020-02-29 20:00:00 224.63\n",
"2020-02-29 19:00:00 225.31\n",
" ... \n",
"2020-01-01 04:00:00 129.56\n",
"2020-01-01 03:00:00 129.57\n",
"2020-01-01 02:00:00 130.37\n",
"2020-01-01 01:00:00 130.14\n",
"2020-01-01 00:00:00 128.34\n",
"Name: Close, Length: 1440, dtype: float64"
]
},
"execution_count": 105,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Get only the Close column showing closing of January and February 2020\n",
"df.loc['2020-01':'2020-02', 'Close']"
]
},
{
"cell_type": "code",
"execution_count": 106,
"id": "b4024017",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"195.16559027777814"
]
},
"execution_count": 106,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Compute the mean\n",
"df.loc['2020-01':'2020-02', 'Close'].mean()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "85b8e352",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "13befab5",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "36f29e36",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "ba24d532",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "4382d2b8",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"id": "fb4a77e9",
"metadata": {},
"source": [
"### c. Resampling using `df.resample()` Method\n",
"- The `df.resample()` is a convenience method for frequency conversion and resampling of time series data. \n",
"- The dataframe on which you call the `resample()` method must have a datetime-like index"
]
},
{
"cell_type": "code",
"execution_count": 107,
"id": "1062d11d",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
"
\n",
" \n",
" \n",
" \n",
" Symbol \n",
" Open \n",
" High \n",
" Low \n",
" Close \n",
" Volume \n",
" dayofweek \n",
" \n",
" \n",
" Date \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" 2020-03-13 20:00:00 \n",
" ETHUSD \n",
" 129.94 \n",
" 131.82 \n",
" 126.87 \n",
" 128.71 \n",
" 1940673.93 \n",
" Friday \n",
" \n",
" \n",
" 2020-03-13 19:00:00 \n",
" ETHUSD \n",
" 119.51 \n",
" 132.02 \n",
" 117.10 \n",
" 129.94 \n",
" 7579741.09 \n",
" Friday \n",
" \n",
" \n",
" 2020-03-13 18:00:00 \n",
" ETHUSD \n",
" 124.47 \n",
" 124.85 \n",
" 115.50 \n",
" 119.51 \n",
" 4898735.81 \n",
" Friday \n",
" \n",
" \n",
" 2020-03-13 17:00:00 \n",
" ETHUSD \n",
" 124.08 \n",
" 127.42 \n",
" 121.63 \n",
" 124.47 \n",
" 2753450.92 \n",
" Friday \n",
" \n",
" \n",
" 2020-03-13 16:00:00 \n",
" ETHUSD \n",
" 124.85 \n",
" 129.51 \n",
" 120.17 \n",
" 124.08 \n",
" 4461424.71 \n",
" Friday \n",
" \n",
" \n",
" ... \n",
" ... \n",
" ... \n",
" ... \n",
" ... \n",
" ... \n",
" ... \n",
" ... \n",
" \n",
" \n",
" 2017-07-01 15:00:00 \n",
" ETHUSD \n",
" 265.74 \n",
" 272.74 \n",
" 265.00 \n",
" 272.57 \n",
" 1500282.55 \n",
" Saturday \n",
" \n",
" \n",
" 2017-07-01 14:00:00 \n",
" ETHUSD \n",
" 268.79 \n",
" 269.90 \n",
" 265.00 \n",
" 265.74 \n",
" 1702536.85 \n",
" Saturday \n",
" \n",
" \n",
" 2017-07-01 13:00:00 \n",
" ETHUSD \n",
" 274.83 \n",
" 274.93 \n",
" 265.00 \n",
" 268.79 \n",
" 3010787.99 \n",
" Saturday \n",
" \n",
" \n",
" 2017-07-01 12:00:00 \n",
" ETHUSD \n",
" 275.01 \n",
" 275.01 \n",
" 271.00 \n",
" 274.83 \n",
" 824362.87 \n",
" Saturday \n",
" \n",
" \n",
" 2017-07-01 11:00:00 \n",
" ETHUSD \n",
" 279.98 \n",
" 279.99 \n",
" 272.10 \n",
" 275.01 \n",
" 679358.87 \n",
" Saturday \n",
" \n",
" \n",
"
\n",
"
23674 rows × 7 columns
\n",
"
"
],
"text/plain": [
" Symbol Open High Low Close Volume \\\n",
"Date \n",
"2020-03-13 20:00:00 ETHUSD 129.94 131.82 126.87 128.71 1940673.93 \n",
"2020-03-13 19:00:00 ETHUSD 119.51 132.02 117.10 129.94 7579741.09 \n",
"2020-03-13 18:00:00 ETHUSD 124.47 124.85 115.50 119.51 4898735.81 \n",
"2020-03-13 17:00:00 ETHUSD 124.08 127.42 121.63 124.47 2753450.92 \n",
"2020-03-13 16:00:00 ETHUSD 124.85 129.51 120.17 124.08 4461424.71 \n",
"... ... ... ... ... ... ... \n",
"2017-07-01 15:00:00 ETHUSD 265.74 272.74 265.00 272.57 1500282.55 \n",
"2017-07-01 14:00:00 ETHUSD 268.79 269.90 265.00 265.74 1702536.85 \n",
"2017-07-01 13:00:00 ETHUSD 274.83 274.93 265.00 268.79 3010787.99 \n",
"2017-07-01 12:00:00 ETHUSD 275.01 275.01 271.00 274.83 824362.87 \n",
"2017-07-01 11:00:00 ETHUSD 279.98 279.99 272.10 275.01 679358.87 \n",
"\n",
" dayofweek \n",
"Date \n",
"2020-03-13 20:00:00 Friday \n",
"2020-03-13 19:00:00 Friday \n",
"2020-03-13 18:00:00 Friday \n",
"2020-03-13 17:00:00 Friday \n",
"2020-03-13 16:00:00 Friday \n",
"... ... \n",
"2017-07-01 15:00:00 Saturday \n",
"2017-07-01 14:00:00 Saturday \n",
"2017-07-01 13:00:00 Saturday \n",
"2017-07-01 12:00:00 Saturday \n",
"2017-07-01 11:00:00 Saturday \n",
"\n",
"[23674 rows x 7 columns]"
]
},
"execution_count": 107,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df"
]
},
{
"cell_type": "markdown",
"id": "b2dcd45f",
"metadata": {},
"source": [
">The given dataframe is showing data on hourly basis. Suppose for analysis purpose I need daily, or weekly, monthly, or yearly data as I am no longer interested in hourly stock prices. So we need to resample our data\n",
">- Down Sampling\n",
">- Up Sampling"
]
},
{
"cell_type": "code",
"execution_count": 108,
"id": "aeee3141",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"Date\n",
"2020-03-13 20:00:00 128.71\n",
"2020-03-13 19:00:00 129.94\n",
"2020-03-13 18:00:00 119.51\n",
"2020-03-13 17:00:00 124.47\n",
"2020-03-13 16:00:00 124.08\n",
" ... \n",
"2017-07-01 15:00:00 272.57\n",
"2017-07-01 14:00:00 265.74\n",
"2017-07-01 13:00:00 268.79\n",
"2017-07-01 12:00:00 274.83\n",
"2017-07-01 11:00:00 275.01\n",
"Name: Close, Length: 23674, dtype: float64"
]
},
"execution_count": 108,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# get the time series of Close column\n",
"df.loc[:, 'Close']"
]
},
{
"cell_type": "code",
"execution_count": 109,
"id": "0fe5bc83",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"Date\n",
"2017-07-01 265.284615\n",
"2017-07-02 269.782500\n",
"2017-07-03 278.882083\n",
"2017-07-04 276.743333\n",
"2017-07-05 265.025833\n",
" ... \n",
"2020-03-09 200.818333\n",
"2020-03-10 201.577500\n",
"2020-03-11 195.910417\n",
"2020-03-12 152.763333\n",
"2020-03-13 124.060476\n",
"Freq: D, Name: Close, Length: 987, dtype: float64"
]
},
"execution_count": 109,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# To get the maximum closing value on daily basis, we resample on Daily basis\n",
"df.loc[:, 'Close'].resample('D').mean()"
]
},
{
"cell_type": "code",
"execution_count": 110,
"id": "9e9002e0",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"Date\n",
"2017-07-31 292.54\n",
"2017-08-31 389.78\n",
"2017-09-30 395.54\n",
"2017-10-31 348.45\n",
"2017-11-30 508.82\n",
"2017-12-31 858.90\n",
"2018-01-31 1418.61\n",
"2018-02-28 1138.68\n",
"2018-03-31 875.99\n",
"2018-04-30 709.00\n",
"2018-05-31 828.00\n",
"2018-06-30 623.89\n",
"2018-07-31 508.23\n",
"2018-08-31 431.84\n",
"2018-09-30 301.51\n",
"2018-10-31 233.20\n",
"2018-11-30 220.36\n",
"2018-12-31 156.07\n",
"2019-01-31 159.43\n",
"2019-02-28 164.08\n",
"2019-03-31 144.99\n",
"2019-04-30 185.32\n",
"2019-05-31 287.08\n",
"2019-06-30 355.31\n",
"2019-07-31 317.14\n",
"2019-08-31 235.50\n",
"2019-09-30 221.90\n",
"2019-10-31 196.07\n",
"2019-11-30 193.66\n",
"2019-12-31 151.55\n",
"2020-01-31 186.62\n",
"2020-02-29 286.39\n",
"2020-03-31 247.62\n",
"Freq: M, Name: Close, dtype: float64"
]
},
"execution_count": 110,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# To get the maximum closing value on monthly basis, we resample on monthly basis\n",
"df.loc[:, 'Close'].resample('M').max()"
]
},
{
"cell_type": "code",
"execution_count": 111,
"id": "a3c9f05e",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"Date\n",
"2017-12-31 858.90\n",
"2018-12-31 1418.61\n",
"2019-12-31 355.31\n",
"2020-12-31 286.39\n",
"Freq: A-DEC, Name: Close, dtype: float64"
]
},
"execution_count": 111,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# To get the maximum closing value on yearly basis, we resample on yearly basis\n",
"df.loc[:, 'Close'].resample('Y').max()"
]
},
{
"cell_type": "markdown",
"id": "fb826f3e",
"metadata": {},
"source": [
">In a similary fashion, we can apply any aggregate function on any of the columns of our time series data"
]
},
{
"cell_type": "code",
"execution_count": 112,
"id": "52e66d0a",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
""
]
},
"execution_count": 112,
"metadata": {},
"output_type": "execute_result"
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAX0AAAESCAYAAAAR2wXeAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjUuMSwgaHR0cHM6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ZaTDSOBxEZkENAGjTrL+l4FTRORrzusEPJNfWOgb11noG9MGp3mnCc9oiD8FivCMfxPGFyc6+fRjeMZHeTMgRRrTCXYh15iTcEYy/QPwuDPAVQJQqKrNwDVAuLNqJdDX66NvAjc6Q+siIqNEJA5jgoCd6RvzeX1E5BM8TTmNeC7ctgyNuxh4RUQuB94Fqpzlm4FGEdmEZzTER/H06NnoDIdbjI9T3BnjL3Yh1xhjQog17xhjTAix0DfGmBBioW+MMSHEQt8YY0KIhb4xxoQQC31jjAkhFvrGGBNCLPSNMSaE/H+ICIKZQQQbDQAAAABJRU5ErkJggg==\n",
"text/plain": [
""
]
},
"metadata": {
"needs_background": "light"
},
"output_type": "display_data"
}
],
"source": [
"%matplotlib inline\n",
"df.loc[:, 'Close'].resample('M').max().plot()"
]
},
{
"cell_type": "code",
"execution_count": 113,
"id": "15f47d53",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
""
]
},
"execution_count": 113,
"metadata": {},
"output_type": "execute_result"
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAX0AAAFmCAYAAACBaEoJAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjUuMSwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/YYfK9AAAACXBIWXMAAAsTAAALEwEAmpwYAAAiYklEQVR4nO3de9RddX3n8feHgKggckm4mAQftEEF6gUzFHXaYtGClzFMFQkzYqzMSkuxOo5dCu1q6YzNLKodKlbBZqEl1AuNl0pmkJuIWi+A4SYETEkNhECERwmVqlATvvPH3oGdk3POc85zLvu3z+/zWmuvnOd3vmfv7++3n3zPfvY++3cUEZiZWR52qzsBMzMbHxd9M7OMuOibmWXERd/MLCMu+mZmGdm97gRmMnfu3Jiamqo7DTOzRrnpppt+HBHzWtuTL/pTU1OsXbu27jTMzBpF0r3t2n16x8wsIy76ZmYZcdE3M8uIi76ZWUZc9M3MMuKib2aWERd9M7OMuOibmWVkxqIv6VOSHpJ0R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GeQO7vDcqyYtrgk5us8emxTimpBjnWPTbfFHNs3MMpL66R0zMxsiF30zs4y46JtVSNou6VZJ6yTdJul/SOr6/0TSlKT/Mq4czQbhom+2s19ExEsj4kjgtcDrgXNmeM0U4KJvjeALuWYVkv4tIvau/Pw84HsUH4t7LvD3wI5b4N8VEd+RdD3wImAjsAr4KMUXWxwH7Al8PCL+dmydMOvCRd+sorXol21bgRcCjwJPRMRjkhYBn4uIxeVNMn8UEW8s45cDB0bEX0jaE/g2cHJEbBxnX8zaSf2OXLMU7LjbcQ/gY+UNMtuBwzvE/zbwYklvKX9+NrCI4i8Bs1q56Jt1UZ7e2Q48RHFu/0HgJRTXwx7r9DLgDyPiqrEkadYHX8g160DSPOATwMeiOA/6bGBLRDwBnAbMKUMfBZ5VeelVwBmS9ijXc3jrVLhmdfGRvtnOniHpVopTOdsoLtyeVz53AfBFSScD1wE/K9u/D2yTdBtwMXA+xSd6bpYkYBo4aTzpm3XnC7lmZhnx6R0zs4y46JuZZcRF38wsIy76ZmYZcdE3M8uIi76ZWUZc9M3MMvL/Acqx8h9dXOyUAAAAAElFTkSuQmCC\n",
"text/plain": [
""
]
},
"metadata": {
"needs_background": "light"
},
"output_type": "display_data"
}
],
"source": [
"%matplotlib inline\n",
"df.loc[:, 'Close'].resample('M').max().plot(kind='bar')"
]
},
{
"cell_type": "code",
"execution_count": 114,
"id": "d371bff9",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
""
]
},
"execution_count": 114,
"metadata": {},
"output_type": "execute_result"
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAX0AAAEECAYAAADEVORYAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjUuMSwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/YYfK9AAAACXBIWXMAAAsTAAALEwEAmpwYAAA4T0lEQVR4nO2deXwV5fX/34ckhH1fRECCsgkKKBG1LiigoFixbsUuamtL60+r1VoL7lVRWm2r1qp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4FcCMaxKs4Ehdfd4mKc6cuHAatVdb3p8qcm09XwNflVV100qdvFzmRdNeGLnr6HSpyJCVuAwe6T8kagUlU/Tcc/gI91+VGT6Wr4mvyqy4+a/KwrOun2L1X/wcnUV4mzAPAl6dbjZ11+1GS6Gr4mv+ryoyY/64r247sZuSLSA/g58HdVLUm3ngB+1OVHTWC66oIfNYE/dflRE/hXVzR8Z/QNwzCM1OE3n75hGIaRQszoG4ZhZBBm9A3DMDIIM/qGYRgZhBl9wzCMDMKMvmF4EJEKEflaRBaJyAIRuVpEavw/EZE8EflJfWk0jEQwo28YoexT1aGqOggnn8rpwM21nJMHmNE3GgQWp28YHkRkt6q28uwfDHyFsxZsL+BJnGXwAC5X1c9F5AvgUJy1UB8H7gOmAifhZGL8l6r+X739EYZRA2b0DcNDdaPvlm3HWb+0GCenyn53bdhnVDVfRE4CrlHVM9z6E3EWE7ldRHKBz4DzVHV1ff4thhEJX2XZNAyfEkiJmwPcLyJDcZbF6xel/qk4ybfOdffb4qwBbEbfSDtm9A2jBlz3TgWwGce3vwkYgjMetj/aaTiLaLxdLyINow7YQK5hREFEOgMPAfer4wdtC2xU1UqcBFtZbtVioLXn1LeBS0Ukx71OPxFpiWH4AOvpG0YozUXkaxxXTjnOwO3f3WMPAC+JyHnABziLgQN8A5SLyALgMeBenIieee5qSUXAWfUj3zBqxgZyDcMwMghz7xiGYWQQZvQNwzAyCDP6hmEYGYQZfcMwjAzCjL5hGEYGYUbfMAwjgzCjbxiGkUH8f7bxLss5OV67AAAAAElFTkSuQmCC\n",
"text/plain": [
""
]
},
"metadata": {
"needs_background": "light"
},
"output_type": "display_data"
}
],
"source": [
"%matplotlib inline\n",
"df.loc[:, 'Close'].plot()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "96931b7b",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "4f885c0c",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "397189a4",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "9382b4ed",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "48028673",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"id": "4b5d3892",
"metadata": {},
"source": [
"# Bonus:"
]
},
{
"cell_type": "markdown",
"id": "ae8d0827",
"metadata": {},
"source": [
"## A. Creating a DatetimeIndex\n",
"- The `pd.date_range()` method returns a range of equally spaced time points as a DatetimeIndex, which is an immutable container for datetimes.\n",
"\n",
"```\n",
"pd.date_range(start=None, end=None, periods=None, freq=None)\n",
"```\n",
"\n",
"- Where,\n",
" - `start` is the left bound (str or datetime)\n",
" - `end` is the right bound (str or datetime)\n",
" - `periods` is the number of periods to generate\n",
" - `freq` can be `s`, `min`, `h`, `d`, `m`, `q`, `y` for seconds, minutes, ....\n",
"\n",
"\n",
"- Out of the four parameters: start, end, periods, and freq, exactly three must be specified"
]
},
{
"cell_type": "code",
"execution_count": 116,
"id": "58429ef0",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"DatetimeIndex(['2022-01-01 00:00:00', '2022-01-01 01:00:00',\n",
" '2022-01-01 02:00:00', '2022-01-01 03:00:00',\n",
" '2022-01-01 04:00:00', '2022-01-01 05:00:00',\n",
" '2022-01-01 06:00:00', '2022-01-01 07:00:00',\n",
" '2022-01-01 08:00:00', '2022-01-01 09:00:00'],\n",
" dtype='datetime64[ns]', freq='H')"
]
},
"execution_count": 116,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"dti = pd.date_range(start='2022/1/1', periods=10, freq='h')\n",
"dti"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "487b7239",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": 117,
"id": "fca10f33",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"DatetimeIndex(['2022-01-01', '2022-01-02', '2022-01-03', '2022-01-04',\n",
" '2022-01-05', '2022-01-06', '2022-01-07', '2022-01-08',\n",
" '2022-01-09', '2022-01-10', '2022-01-11', '2022-01-12',\n",
" '2022-01-13', '2022-01-14', '2022-01-15', '2022-01-16',\n",
" '2022-01-17', '2022-01-18', '2022-01-19', '2022-01-20',\n",
" '2022-01-21', '2022-01-22', '2022-01-23', '2022-01-24',\n",
" '2022-01-25', '2022-01-26', '2022-01-27', '2022-01-28',\n",
" '2022-01-29', '2022-01-30', '2022-01-31'],\n",
" dtype='datetime64[ns]', freq='D')"
]
},
"execution_count": 117,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"dti = pd.date_range(start='2022/1/1', end='2022/1/31', freq='d')\n",
"dti"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "acbe75f3",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": 118,
"id": "bd54b906",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"DatetimeIndex(['2022-01-03', '2022-01-04', '2022-01-05', '2022-01-06',\n",
" '2022-01-07', '2022-01-10', '2022-01-11', '2022-01-12',\n",
" '2022-01-13', '2022-01-14', '2022-01-17', '2022-01-18',\n",
" '2022-01-19', '2022-01-20', '2022-01-21', '2022-01-24',\n",
" '2022-01-25', '2022-01-26', '2022-01-27', '2022-01-28',\n",
" '2022-01-31'],\n",
" dtype='datetime64[ns]', freq='B')"
]
},
"execution_count": 118,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# here freq=B mean include the business days and exclude the weekends\n",
"dti = pd.date_range(start='2022/1/1', end='2022/1/31', freq='B')\n",
"dti"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "db20feef",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": 119,
"id": "f59ac394",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"pandas.core.indexes.datetimes.DatetimeIndex"
]
},
"execution_count": 119,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"type(dti)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "8f876fbd",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "be0f1619",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": 120,
"id": "f8d489eb",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"0 2022-01-01\n",
"1 2022-01-02\n",
"2 2022-01-03\n",
"3 2022-01-04\n",
"4 2022-01-05\n",
"5 2022-01-06\n",
"6 2022-01-07\n",
"7 2022-01-08\n",
"8 2022-01-09\n",
"9 2022-01-10\n",
"dtype: datetime64[ns]"
]
},
"execution_count": 120,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"s = pd.Series(pd.date_range(\"2022-01-01\", periods=10, freq=\"d\"))\n",
"s"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "6639556d",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": 121,
"id": "61c272b0",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"0 Saturday\n",
"1 Sunday\n",
"2 Monday\n",
"3 Tuesday\n",
"4 Wednesday\n",
"5 Thursday\n",
"6 Friday\n",
"7 Saturday\n",
"8 Sunday\n",
"9 Monday\n",
"dtype: object"
]
},
"execution_count": 121,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"s.dt.day_name()"
]
},
{
"cell_type": "code",
"execution_count": 122,
"id": "1d424b85",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"pandas._libs.tslibs.timestamps.Timestamp"
]
},
"execution_count": 122,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"type(s[0])"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "80fc43bd",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"id": "098fef2c",
"metadata": {},
"source": [
"### b. A sample dataset w/o Datetime"
]
},
{
"cell_type": "code",
"execution_count": 123,
"id": "868675e9",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
"
\n",
" \n",
" \n",
" \n",
" day \n",
" temperature \n",
" humidity \n",
" \n",
" \n",
" \n",
" \n",
" 0 \n",
" Monday \n",
" 30 \n",
" 70 \n",
" \n",
" \n",
" 1 \n",
" Tuesday \n",
" 34 \n",
" 65 \n",
" \n",
" \n",
" 2 \n",
" Wednesday \n",
" 28 \n",
" 68 \n",
" \n",
" \n",
" 3 \n",
" Thursday \n",
" 35 \n",
" 72 \n",
" \n",
" \n",
" 4 \n",
" Friday \n",
" 32 \n",
" 69 \n",
" \n",
" \n",
" 5 \n",
" Monday \n",
" 37 \n",
" 71 \n",
" \n",
" \n",
" 6 \n",
" Tuesday \n",
" 26 \n",
" 70 \n",
" \n",
" \n",
" 7 \n",
" Monday \n",
" 33 \n",
" 66 \n",
" \n",
" \n",
" 8 \n",
" Tuesday \n",
" 28 \n",
" 76 \n",
" \n",
" \n",
" 9 \n",
" Wednesday \n",
" 29 \n",
" 54 \n",
" \n",
" \n",
" 10 \n",
" Monday \n",
" 45 \n",
" 77 \n",
" \n",
" \n",
" 11 \n",
" Tuesday \n",
" 40 \n",
" 54 \n",
" \n",
" \n",
" 12 \n",
" Wednesday \n",
" 34 \n",
" 67 \n",
" \n",
" \n",
" 13 \n",
" Thursday \n",
" 32 \n",
" 79 \n",
" \n",
" \n",
" 14 \n",
" Friday \n",
" 31 \n",
" 80 \n",
" \n",
" \n",
" 15 \n",
" Thursday \n",
" 26 \n",
" 78 \n",
" \n",
" \n",
" 16 \n",
" Friday \n",
" 28 \n",
" 54 \n",
" \n",
" \n",
" 17 \n",
" Monday \n",
" 21 \n",
" 52 \n",
" \n",
" \n",
" 18 \n",
" Tuesday \n",
" 22 \n",
" 64 \n",
" \n",
" \n",
" 19 \n",
" Wednesday \n",
" 21 \n",
" 61 \n",
" \n",
" \n",
"
\n",
"
"
],
"text/plain": [
" day temperature humidity\n",
"0 Monday 30 70\n",
"1 Tuesday 34 65\n",
"2 Wednesday 28 68\n",
"3 Thursday 35 72\n",
"4 Friday 32 69\n",
"5 Monday 37 71\n",
"6 Tuesday 26 70\n",
"7 Monday 33 66\n",
"8 Tuesday 28 76\n",
"9 Wednesday 29 54\n",
"10 Monday 45 77\n",
"11 Tuesday 40 54\n",
"12 Wednesday 34 67\n",
"13 Thursday 32 79\n",
"14 Friday 31 80\n",
"15 Thursday 26 78\n",
"16 Friday 28 54\n",
"17 Monday 21 52\n",
"18 Tuesday 22 64\n",
"19 Wednesday 21 61"
]
},
"execution_count": 123,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"import pandas as pd\n",
"\n",
"# this dataframe has no datecolumn\n",
"df = pd.read_csv(\"datasets/no_date.csv\")\n",
"df"
]
},
{
"cell_type": "code",
"execution_count": 124,
"id": "09213e6d",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"(20, 3)"
]
},
"execution_count": 124,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df.shape"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "790b8b58",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "c79f1ae9",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"id": "49af4d9f",
"metadata": {},
"source": [
"### c. Create a DateTime Object and Set it as Index to make the above dataset a TimeSeries Data"
]
},
{
"cell_type": "code",
"execution_count": 125,
"id": "6c3c28c0",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"DatetimeIndex(['2022-01-01', '2022-01-02', '2022-01-03', '2022-01-04',\n",
" '2022-01-05', '2022-01-06', '2022-01-07', '2022-01-08',\n",
" '2022-01-09', '2022-01-10', '2022-01-11', '2022-01-12',\n",
" '2022-01-13', '2022-01-14', '2022-01-15', '2022-01-16',\n",
" '2022-01-17', '2022-01-18', '2022-01-19', '2022-01-20'],\n",
" dtype='datetime64[ns]', freq='D')"
]
},
"execution_count": 125,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"dti = pd.date_range(start='2022/1/1', end='2022/1/20', freq='d')\n",
"dti"
]
},
{
"cell_type": "code",
"execution_count": 126,
"id": "3d8877ce",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
"
\n",
" \n",
" \n",
" \n",
" day \n",
" temperature \n",
" humidity \n",
" \n",
" \n",
" \n",
" \n",
" 2022-01-01 \n",
" Monday \n",
" 30 \n",
" 70 \n",
" \n",
" \n",
" 2022-01-02 \n",
" Tuesday \n",
" 34 \n",
" 65 \n",
" \n",
" \n",
" 2022-01-03 \n",
" Wednesday \n",
" 28 \n",
" 68 \n",
" \n",
" \n",
" 2022-01-04 \n",
" Thursday \n",
" 35 \n",
" 72 \n",
" \n",
" \n",
" 2022-01-05 \n",
" Friday \n",
" 32 \n",
" 69 \n",
" \n",
" \n",
" 2022-01-06 \n",
" Monday \n",
" 37 \n",
" 71 \n",
" \n",
" \n",
" 2022-01-07 \n",
" Tuesday \n",
" 26 \n",
" 70 \n",
" \n",
" \n",
" 2022-01-08 \n",
" Monday \n",
" 33 \n",
" 66 \n",
" \n",
" \n",
" 2022-01-09 \n",
" Tuesday \n",
" 28 \n",
" 76 \n",
" \n",
" \n",
" 2022-01-10 \n",
" Wednesday \n",
" 29 \n",
" 54 \n",
" \n",
" \n",
" 2022-01-11 \n",
" Monday \n",
" 45 \n",
" 77 \n",
" \n",
" \n",
" 2022-01-12 \n",
" Tuesday \n",
" 40 \n",
" 54 \n",
" \n",
" \n",
" 2022-01-13 \n",
" Wednesday \n",
" 34 \n",
" 67 \n",
" \n",
" \n",
" 2022-01-14 \n",
" Thursday \n",
" 32 \n",
" 79 \n",
" \n",
" \n",
" 2022-01-15 \n",
" Friday \n",
" 31 \n",
" 80 \n",
" \n",
" \n",
" 2022-01-16 \n",
" Thursday \n",
" 26 \n",
" 78 \n",
" \n",
" \n",
" 2022-01-17 \n",
" Friday \n",
" 28 \n",
" 54 \n",
" \n",
" \n",
" 2022-01-18 \n",
" Monday \n",
" 21 \n",
" 52 \n",
" \n",
" \n",
" 2022-01-19 \n",
" Tuesday \n",
" 22 \n",
" 64 \n",
" \n",
" \n",
" 2022-01-20 \n",
" Wednesday \n",
" 21 \n",
" 61 \n",
" \n",
" \n",
"
\n",
"
"
],
"text/plain": [
" day temperature humidity\n",
"2022-01-01 Monday 30 70\n",
"2022-01-02 Tuesday 34 65\n",
"2022-01-03 Wednesday 28 68\n",
"2022-01-04 Thursday 35 72\n",
"2022-01-05 Friday 32 69\n",
"2022-01-06 Monday 37 71\n",
"2022-01-07 Tuesday 26 70\n",
"2022-01-08 Monday 33 66\n",
"2022-01-09 Tuesday 28 76\n",
"2022-01-10 Wednesday 29 54\n",
"2022-01-11 Monday 45 77\n",
"2022-01-12 Tuesday 40 54\n",
"2022-01-13 Wednesday 34 67\n",
"2022-01-14 Thursday 32 79\n",
"2022-01-15 Friday 31 80\n",
"2022-01-16 Thursday 26 78\n",
"2022-01-17 Friday 28 54\n",
"2022-01-18 Monday 21 52\n",
"2022-01-19 Tuesday 22 64\n",
"2022-01-20 Wednesday 21 61"
]
},
"execution_count": 126,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# use the set_index function, and make the above created date ranges, index of your dataframe\n",
"df.set_index(dti, inplace=True)\n",
"df"
]
},
{
"cell_type": "markdown",
"id": "122180a7",
"metadata": {},
"source": [
"Does the day column match with the dates? Can you think of a way to reset the day column as per the dates?"
]
},
{
"cell_type": "code",
"execution_count": 127,
"id": "f19e5dd6",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
"
\n",
" \n",
" \n",
" \n",
" day \n",
" temperature \n",
" humidity \n",
" correct day \n",
" \n",
" \n",
" \n",
" \n",
" 2022-01-01 \n",
" Monday \n",
" 30 \n",
" 70 \n",
" Saturday \n",
" \n",
" \n",
" 2022-01-02 \n",
" Tuesday \n",
" 34 \n",
" 65 \n",
" Sunday \n",
" \n",
" \n",
" 2022-01-03 \n",
" Wednesday \n",
" 28 \n",
" 68 \n",
" Monday \n",
" \n",
" \n",
" 2022-01-04 \n",
" Thursday \n",
" 35 \n",
" 72 \n",
" Tuesday \n",
" \n",
" \n",
" 2022-01-05 \n",
" Friday \n",
" 32 \n",
" 69 \n",
" Wednesday \n",
" \n",
" \n",
" 2022-01-06 \n",
" Monday \n",
" 37 \n",
" 71 \n",
" Thursday \n",
" \n",
" \n",
" 2022-01-07 \n",
" Tuesday \n",
" 26 \n",
" 70 \n",
" Friday \n",
" \n",
" \n",
" 2022-01-08 \n",
" Monday \n",
" 33 \n",
" 66 \n",
" Saturday \n",
" \n",
" \n",
" 2022-01-09 \n",
" Tuesday \n",
" 28 \n",
" 76 \n",
" Sunday \n",
" \n",
" \n",
" 2022-01-10 \n",
" Wednesday \n",
" 29 \n",
" 54 \n",
" Monday \n",
" \n",
" \n",
" 2022-01-11 \n",
" Monday \n",
" 45 \n",
" 77 \n",
" Tuesday \n",
" \n",
" \n",
" 2022-01-12 \n",
" Tuesday \n",
" 40 \n",
" 54 \n",
" Wednesday \n",
" \n",
" \n",
" 2022-01-13 \n",
" Wednesday \n",
" 34 \n",
" 67 \n",
" Thursday \n",
" \n",
" \n",
" 2022-01-14 \n",
" Thursday \n",
" 32 \n",
" 79 \n",
" Friday \n",
" \n",
" \n",
" 2022-01-15 \n",
" Friday \n",
" 31 \n",
" 80 \n",
" Saturday \n",
" \n",
" \n",
" 2022-01-16 \n",
" Thursday \n",
" 26 \n",
" 78 \n",
" Sunday \n",
" \n",
" \n",
" 2022-01-17 \n",
" Friday \n",
" 28 \n",
" 54 \n",
" Monday \n",
" \n",
" \n",
" 2022-01-18 \n",
" Monday \n",
" 21 \n",
" 52 \n",
" Tuesday \n",
" \n",
" \n",
" 2022-01-19 \n",
" Tuesday \n",
" 22 \n",
" 64 \n",
" Wednesday \n",
" \n",
" \n",
" 2022-01-20 \n",
" Wednesday \n",
" 21 \n",
" 61 \n",
" Thursday \n",
" \n",
" \n",
"
\n",
"
"
],
"text/plain": [
" day temperature humidity correct day\n",
"2022-01-01 Monday 30 70 Saturday\n",
"2022-01-02 Tuesday 34 65 Sunday\n",
"2022-01-03 Wednesday 28 68 Monday\n",
"2022-01-04 Thursday 35 72 Tuesday\n",
"2022-01-05 Friday 32 69 Wednesday\n",
"2022-01-06 Monday 37 71 Thursday\n",
"2022-01-07 Tuesday 26 70 Friday\n",
"2022-01-08 Monday 33 66 Saturday\n",
"2022-01-09 Tuesday 28 76 Sunday\n",
"2022-01-10 Wednesday 29 54 Monday\n",
"2022-01-11 Monday 45 77 Tuesday\n",
"2022-01-12 Tuesday 40 54 Wednesday\n",
"2022-01-13 Wednesday 34 67 Thursday\n",
"2022-01-14 Thursday 32 79 Friday\n",
"2022-01-15 Friday 31 80 Saturday\n",
"2022-01-16 Thursday 26 78 Sunday\n",
"2022-01-17 Friday 28 54 Monday\n",
"2022-01-18 Monday 21 52 Tuesday\n",
"2022-01-19 Tuesday 22 64 Wednesday\n",
"2022-01-20 Wednesday 21 61 Thursday"
]
},
"execution_count": 127,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df['correct day'] = list(pd.Series(dti.day_name()))\n",
"df"
]
},
{
"cell_type": "markdown",
"id": "3d7aaead",
"metadata": {},
"source": [
">**Students are advised to explore the Pandas `Period` and `PeriodIndex` data structures at their own**"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "25d43d56",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "28297217",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "875fae35",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "53a87336",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "e0ea7da9",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "394e0030",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "3b9e5334",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "a3868ad7",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "5f734b79",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "83b6a27b",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "c937d4b7",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "4861c314",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "c034d323",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "d6c44a4a",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "670674ba",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "609d3be1",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "2dbc0c04",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "538507c9",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "4e9d1027",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "23f65db7",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "a2eae784",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "4eea3971",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "e033ce65",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "d1d5dfce",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "948f2367",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "6c3de44f",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "52adb6ab",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "2272d230",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "0e5ec6a3",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "8cc136c4",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "c3733bd4",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "0ed5ddf7",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "f9b11122",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "2694814e",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"id": "39060aab",
"metadata": {},
"source": [
"## B. Creating a Period and Periodindex"
]
},
{
"cell_type": "markdown",
"id": "9452a840",
"metadata": {},
"source": [
"### a. Have an Insight about Period"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "cc6be8b3",
"metadata": {},
"outputs": [],
"source": [
"import pandas as pd\n",
"\n",
"# let us passed as argument to the Pandas Period function and notice the output\n",
"# A-DEC shows that 2021 is an annual period and end at December\n",
"y = pd.Period('2021')\n",
"y"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "552fb833",
"metadata": {},
"outputs": [],
"source": [
"# you can check different attributes related to this period\n",
"# for instance check the start time, which is 1st january\n",
"y.start_time"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "d578ce09",
"metadata": {},
"outputs": [],
"source": [
"# check the end time which is obviously 31st december\n",
"y.end_time"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "e031d495",
"metadata": {},
"outputs": [],
"source": [
"# check whether it is leap year\n",
"y.is_leap_year"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "66060548",
"metadata": {},
"outputs": [],
"source": [
"# you can also create a monthly period and check its start and end time\n",
"m = pd.Period('2021-8')\n",
"print(\"period: \", m)\n",
"\n",
"print(\"start time: \",m.start_time)\n",
"print(\"end time: \",m.end_time)\n",
"\n",
"# performing arithmatic operation\n",
"print(\"Next monthly period will be: \",m+1)\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "83ee8c66",
"metadata": {},
"outputs": [],
"source": [
"# you can compute the daily and hourly period as well\n",
"import pandas as pd\n",
"d= pd.Period('2016-02-28', freq='D')\n",
"print(d)\n",
"\n",
"print(d.start_time)\n",
"\n",
"print(d.end_time)\n",
"print(d+1)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "1c5c454f",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"id": "20b28aa7",
"metadata": {},
"source": [
"### b. Have an Insight about Period Index\n",
"The above discuused periods can also be used as index in a DataFrame"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "f340bab5",
"metadata": {},
"outputs": [],
"source": [
"# create a quarterly period b/w 2011 to 2017\n",
"idx = pd.period_range('2011', '2017', freq='q')\n",
"idx"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "02866b61",
"metadata": {},
"outputs": [],
"source": [
"import numpy as np\n",
"\n",
"# set this period as index of random series\n",
"ps = pd.Series(np.random.randint(10,100,len(idx)), idx)\n",
"ps"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "c544298b",
"metadata": {},
"outputs": [],
"source": [
"# you can partially retrieve data or retrieve data in chunks using these periods\n",
"ps['2016']"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "f98fda1f",
"metadata": {},
"outputs": [],
"source": [
"ps['2016':'2017']"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "d4e2ffcc",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "86f80fad",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "9a2450f6",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "aa99b61c",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "b2e55b7a",
"metadata": {},
"outputs": [],
"source": []
}
],
"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.7"
}
},
"nbformat": 4,
"nbformat_minor": 5
}