{ "nbformat": 4, "nbformat_minor": 0, "metadata": { "colab": { "provenance": [] }, "kernelspec": { "name": "python3", "display_name": "Python 3" }, "language_info": { "name": "python" } }, "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": { "id": "IJFIwaA_zVR2" }, "outputs": [], "source": [ "import numpy as np\n", "import pandas as pd\n", "\n", "import os\n", "for dirname, _, filenames in os.walk('/kaggle/input'):\n", " print(os.path.join(dirname, filename))" ] }, { "cell_type": "code", "source": [ "train=pd.read_csv('/content/data (1).csv')\n", "train.sample(20)" ], "metadata": { "colab": { "base_uri": "https://localhost:8080/", "height": 1000 }, "id": "NUWS2DVTzjkG", "outputId": "e15fd089-e382-49f0-ea0b-050e547ecc3d" }, "execution_count": 2, "outputs": [ { "output_type": "execute_result", "data": { "text/plain": [ " Date Open High Low Close \\\n", "7186 2008-09-08 00:00:00-04:00 13.022795 13.097282 12.737262 13.016587 \n", "7538 2010-02-01 00:00:00-05:00 12.606479 12.787774 12.587055 12.697127 \n", "9176 2016-08-03 00:00:00-04:00 27.629613 27.775459 27.540488 27.751152 \n", "633 1982-09-17 00:00:00-04:00 0.197472 0.197472 0.196020 0.196020 \n", "2063 1988-05-13 00:00:00-04:00 0.553211 0.561923 0.544499 0.555389 \n", "5290 2001-02-21 00:00:00-05:00 17.642546 18.638496 17.357988 17.500267 \n", "5828 2003-04-16 00:00:00-04:00 10.291652 10.497944 10.199967 10.406259 \n", "9969 2019-09-27 00:00:00-04:00 44.415860 44.933445 44.161452 44.547447 \n", "8736 2014-11-03 00:00:00-05:00 25.771054 26.281748 25.755809 26.152170 \n", "9576 2018-03-07 00:00:00-05:00 42.411700 43.518902 42.344083 43.375217 \n", "6442 2005-09-22 00:00:00-04:00 14.289544 14.441312 14.190311 14.336242 \n", "3511 1994-02-02 00:00:00-05:00 2.269937 2.304994 2.252408 2.287465 \n", "3259 1993-02-04 00:00:00-05:00 1.908102 1.929933 1.851339 1.908102 \n", "3754 1995-01-20 00:00:00-05:00 2.474260 2.483050 2.413283 2.419325 \n", "2405 1989-09-20 00:00:00-04:00 0.535787 0.548855 0.531431 0.544499 \n", "2468 1989-12-19 00:00:00-05:00 0.522719 0.544499 0.522719 0.540143 \n", "7161 2008-08-01 00:00:00-04:00 13.830115 13.891802 13.558694 13.786935 \n", "2852 1991-06-27 00:00:00-04:00 0.805859 0.810215 0.788435 0.794969 \n", "303 1981-05-29 00:00:00-04:00 0.239580 0.239580 0.238127 0.238127 \n", "3736 1994-12-23 00:00:00-05:00 2.219364 2.228154 2.206179 2.212772 \n", "\n", " Volume Dividends Stock Splits \n", "7186 63278600 0.00 0.0 \n", "7538 50338300 0.00 0.0 \n", "9176 18388800 0.26 0.0 \n", "633 42432000 0.00 0.0 \n", "2063 22377600 0.00 0.0 \n", "5290 51582200 0.00 0.0 \n", "5828 106294400 0.00 0.0 \n", "9969 14845700 0.00 0.0 \n", "8736 28703600 0.00 0.0 \n", "9576 31801900 0.00 0.0 \n", "6442 42372800 0.00 0.0 \n", "3511 50043200 0.00 0.0 \n", "3259 171360000 0.00 0.0 \n", "3754 146233600 0.00 0.0 \n", "2405 35619200 0.00 0.0 \n", "2468 40672000 0.00 0.0 \n", "7161 42123200 0.00 0.0 \n", "2852 46534400 0.00 0.0 \n", "303 27091200 0.00 0.0 \n", "3736 23969600 0.00 0.0 " ], "text/html": [ "\n", "
\n", "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
DateOpenHighLowCloseVolumeDividendsStock Splits
71862008-09-08 00:00:00-04:0013.02279513.09728212.73726213.016587632786000.000.0
75382010-02-01 00:00:00-05:0012.60647912.78777412.58705512.697127503383000.000.0
91762016-08-03 00:00:00-04:0027.62961327.77545927.54048827.751152183888000.260.0
6331982-09-17 00:00:00-04:000.1974720.1974720.1960200.196020424320000.000.0
20631988-05-13 00:00:00-04:000.5532110.5619230.5444990.555389223776000.000.0
52902001-02-21 00:00:00-05:0017.64254618.63849617.35798817.500267515822000.000.0
58282003-04-16 00:00:00-04:0010.29165210.49794410.19996710.4062591062944000.000.0
99692019-09-27 00:00:00-04:0044.41586044.93344544.16145244.547447148457000.000.0
87362014-11-03 00:00:00-05:0025.77105426.28174825.75580926.152170287036000.000.0
95762018-03-07 00:00:00-05:0042.41170043.51890242.34408343.375217318019000.000.0
64422005-09-22 00:00:00-04:0014.28954414.44131214.19031114.336242423728000.000.0
35111994-02-02 00:00:00-05:002.2699372.3049942.2524082.287465500432000.000.0
32591993-02-04 00:00:00-05:001.9081021.9299331.8513391.9081021713600000.000.0
37541995-01-20 00:00:00-05:002.4742602.4830502.4132832.4193251462336000.000.0
24051989-09-20 00:00:00-04:000.5357870.5488550.5314310.544499356192000.000.0
24681989-12-19 00:00:00-05:000.5227190.5444990.5227190.540143406720000.000.0
71612008-08-01 00:00:00-04:0013.83011513.89180213.55869413.786935421232000.000.0
28521991-06-27 00:00:00-04:000.8058590.8102150.7884350.794969465344000.000.0
3031981-05-29 00:00:00-04:000.2395800.2395800.2381270.238127270912000.000.0
37361994-12-23 00:00:00-05:002.2193642.2281542.2061792.212772239696000.000.0
\n", "
\n", "
\n", "\n", "
\n", " \n", "\n", " \n", "\n", " \n", "
\n", "\n", "\n", "
\n", " \n", "\n", "\n", "\n", " \n", "
\n", "\n", "
\n", "
\n" ], "application/vnd.google.colaboratory.intrinsic+json": { "type": "dataframe", "repr_error": "0" } }, "metadata": {}, "execution_count": 2 } ] }, { "cell_type": "code", "source": [ "train.describe()" ], "metadata": { "colab": { "base_uri": "https://localhost:8080/", "height": 338 }, "id": "fQDcHcNmzr5q", "outputId": "9ddd067d-8647-489f-87c9-a4979a339ff4" }, "execution_count": 3, "outputs": [ { "output_type": "execute_result", "data": { "text/plain": [ " Open High Low Close Volume \\\n", "count 11289.000000 11289.000000 11289.000000 11289.000000 1.128900e+04 \n", "mean 14.986168 15.185892 14.787731 14.985933 5.064025e+07 \n", "std 14.708247 14.892642 14.526521 14.709644 3.475946e+07 \n", "min 0.121968 0.121968 0.120516 0.120516 0.000000e+00 \n", "25% 0.810214 0.827638 0.797147 0.814571 2.744880e+07 \n", "50% 12.757638 12.917269 12.590077 12.742243 4.456490e+07 \n", "75% 22.624974 22.879999 22.350709 22.617407 6.459720e+07 \n", "max 62.028760 62.292520 60.600833 62.083344 5.677088e+08 \n", "\n", " Dividends Stock Splits \n", "count 11289.000000 11289.000000 \n", "mean 0.001581 0.001373 \n", "std 0.019592 0.051749 \n", "min 0.000000 0.000000 \n", "25% 0.000000 0.000000 \n", "50% 0.000000 0.000000 \n", "75% 0.000000 0.000000 \n", "max 0.365000 2.000000 " ], "text/html": [ "\n", "
\n", "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
OpenHighLowCloseVolumeDividendsStock Splits
count11289.00000011289.00000011289.00000011289.0000001.128900e+0411289.00000011289.000000
mean14.98616815.18589214.78773114.9859335.064025e+070.0015810.001373
std14.70824714.89264214.52652114.7096443.475946e+070.0195920.051749
min0.1219680.1219680.1205160.1205160.000000e+000.0000000.000000
25%0.8102140.8276380.7971470.8145712.744880e+070.0000000.000000
50%12.75763812.91726912.59007712.7422434.456490e+070.0000000.000000
75%22.62497422.87999922.35070922.6174076.459720e+070.0000000.000000
max62.02876062.29252060.60083362.0833445.677088e+080.3650002.000000
\n", "
\n", "
\n", "\n", "
\n", " \n", "\n", " \n", "\n", " \n", "
\n", "\n", "\n", "
\n", " \n", "\n", "\n", "\n", " \n", "
\n", "\n", "
\n", "
\n" ], "application/vnd.google.colaboratory.intrinsic+json": { "type": "dataframe", "summary": "{\n \"name\": \"train\",\n \"rows\": 8,\n \"fields\": [\n {\n \"column\": \"Open\",\n \"properties\": {\n \"dtype\": \"number\",\n \"std\": 3984.844329358589,\n \"min\": 0.121967708,\n \"max\": 11289.0,\n \"num_unique_values\": 8,\n \"samples\": [\n 14.986167789582247,\n 12.75763813,\n 11289.0\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"High\",\n \"properties\": {\n \"dtype\": \"number\",\n \"std\": 3984.79014832723,\n \"min\": 0.121967708,\n \"max\": 11289.0,\n \"num_unique_values\": 8,\n \"samples\": [\n 15.18589170801116,\n 12.91726892,\n 11289.0\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"Low\",\n \"properties\": {\n \"dtype\": \"number\",\n \"std\": 3984.9565335203015,\n \"min\": 0.120515808,\n \"max\": 11289.0,\n \"num_unique_values\": 8,\n \"samples\": [\n 14.78773124896368,\n 12.5900769,\n 11289.0\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"Close\",\n \"properties\": {\n \"dtype\": \"number\",\n \"std\": 3984.8426124818216,\n \"min\": 0.120515808,\n \"max\": 11289.0,\n \"num_unique_values\": 8,\n \"samples\": [\n 14.98593259460652,\n 12.74224281,\n 11289.0\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"Volume\",\n \"properties\": {\n \"dtype\": \"number\",\n \"std\": 190869768.6232143,\n \"min\": 0.0,\n \"max\": 567708800.0,\n \"num_unique_values\": 8,\n \"samples\": [\n 50640251.44831251,\n 44564900.0,\n 11289.0\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"Dividends\",\n \"properties\": {\n \"dtype\": \"number\",\n \"std\": 3991.2447237177803,\n \"min\": 0.0,\n \"max\": 11289.0,\n \"num_unique_values\": 5,\n \"samples\": [\n 0.0015811298609265656,\n 0.365,\n 0.019592219401798217\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"Stock Splits\",\n \"properties\": {\n \"dtype\": \"number\",\n \"std\": 3991.160588947089,\n \"min\": 0.0,\n \"max\": 11289.0,\n \"num_unique_values\": 5,\n \"samples\": [\n 0.0013730179821064754,\n 2.0,\n 0.05174892897105917\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n }\n ]\n}" } }, "metadata": {}, "execution_count": 3 } ] }, { "cell_type": "code", "source": [ "train.info()" ], "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "dtQnku8Fzu-B", "outputId": "09bfe0ba-942c-445d-afee-ff5c0ee62583" }, "execution_count": 4, "outputs": [ { "output_type": "stream", "name": "stdout", "text": [ "\n", "RangeIndex: 11289 entries, 0 to 11288\n", "Data columns (total 8 columns):\n", " # Column Non-Null Count Dtype \n", "--- ------ -------------- ----- \n", " 0 Date 11289 non-null object \n", " 1 Open 11289 non-null float64\n", " 2 High 11289 non-null float64\n", " 3 Low 11289 non-null float64\n", " 4 Close 11289 non-null float64\n", " 5 Volume 11289 non-null int64 \n", " 6 Dividends 11289 non-null float64\n", " 7 Stock Splits 11289 non-null float64\n", "dtypes: float64(6), int64(1), object(1)\n", "memory usage: 705.7+ KB\n" ] } ] }, { "cell_type": "code", "source": [ "null_val = train.isnull().sum()\n", "null_val" ], "metadata": { "colab": { "base_uri": "https://localhost:8080/", "height": 335 }, "id": "CKAJ70HPzw77", "outputId": "69373091-e085-434f-8a7f-d918ff8c7180" }, "execution_count": 6, "outputs": [ { "output_type": "execute_result", "data": { "text/plain": [ "Date 0\n", "Open 0\n", "High 0\n", "Low 0\n", "Close 0\n", "Volume 0\n", "Dividends 0\n", "Stock Splits 0\n", "dtype: int64" ], "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
0
Date0
Open0
High0
Low0
Close0
Volume0
Dividends0
Stock Splits0
\n", "

" ] }, "metadata": {}, "execution_count": 6 } ] }, { "cell_type": "code", "source": [ "nan_val = train.isna().sum()\n", "nan_val" ], "metadata": { "colab": { "base_uri": "https://localhost:8080/", "height": 335 }, "id": "DJ2jzMTkz-xo", "outputId": "22ec787b-ecd8-4f37-9b7b-d7234fdb00a6" }, "execution_count": 7, "outputs": [ { "output_type": "execute_result", "data": { "text/plain": [ "Date 0\n", "Open 0\n", "High 0\n", "Low 0\n", "Close 0\n", "Volume 0\n", "Dividends 0\n", "Stock Splits 0\n", "dtype: int64" ], "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
0
Date0
Open0
High0
Low0
Close0
Volume0
Dividends0
Stock Splits0
\n", "

" ] }, "metadata": {}, "execution_count": 7 } ] }, { "cell_type": "code", "source": [ "train['Date'] = pd.to_datetime(train['Date'])\n", "\n", "train.set_index('Date', inplace=True)\n", "\n", "train.head()" ], "metadata": { "colab": { "base_uri": "https://localhost:8080/", "height": 570 }, "id": "pJrx72DN0DJI", "outputId": "19510354-a8aa-425b-c1ec-1a20a69f2761" }, "execution_count": 8, "outputs": [ { "output_type": "stream", "name": "stderr", "text": [ ":1: FutureWarning: In a future version of pandas, parsing datetimes with mixed time zones will raise an error unless `utc=True`. Please specify `utc=True` to opt in to the new behaviour and silence this warning. To create a `Series` with mixed offsets and `object` dtype, please use `apply` and `datetime.datetime.strptime`\n", " train['Date'] = pd.to_datetime(train['Date'])\n" ] }, { "output_type": "execute_result", "data": { "text/plain": [ " Open High Low Close Volume \\\n", "Date \n", "1980-03-17 00:00:00-05:00 0.181500 0.184404 0.181500 0.181500 10924800 \n", "1980-03-18 00:00:00-05:00 0.181500 0.182952 0.180048 0.180048 17068800 \n", "1980-03-19 00:00:00-05:00 0.184404 0.187308 0.184404 0.184404 18508800 \n", "1980-03-20 00:00:00-05:00 0.184403 0.186581 0.183678 0.183678 11174400 \n", "1980-03-21 00:00:00-05:00 0.180048 0.180048 0.177143 0.177143 12172800 \n", "\n", " Dividends Stock Splits \n", "Date \n", "1980-03-17 00:00:00-05:00 0.0 0.0 \n", "1980-03-18 00:00:00-05:00 0.0 0.0 \n", "1980-03-19 00:00:00-05:00 0.0 0.0 \n", "1980-03-20 00:00:00-05:00 0.0 0.0 \n", "1980-03-21 00:00:00-05:00 0.0 0.0 " ], "text/html": [ "\n", "
\n", "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
OpenHighLowCloseVolumeDividendsStock Splits
Date
1980-03-17 00:00:00-05:000.1815000.1844040.1815000.181500109248000.00.0
1980-03-18 00:00:00-05:000.1815000.1829520.1800480.180048170688000.00.0
1980-03-19 00:00:00-05:000.1844040.1873080.1844040.184404185088000.00.0
1980-03-20 00:00:00-05:000.1844030.1865810.1836780.183678111744000.00.0
1980-03-21 00:00:00-05:000.1800480.1800480.1771430.177143121728000.00.0
\n", "
\n", "
\n", "\n", "
\n", " \n", "\n", " \n", "\n", " \n", "
\n", "\n", "\n", "
\n", " \n", "\n", "\n", "\n", " \n", "
\n", "\n", "
\n", "
\n" ], "application/vnd.google.colaboratory.intrinsic+json": { "type": "dataframe", "variable_name": "train", "summary": "{\n \"name\": \"train\",\n \"rows\": 11289,\n \"fields\": [\n {\n \"column\": \"Date\",\n \"properties\": {\n \"dtype\": \"string\",\n \"num_unique_values\": 11289,\n \"samples\": [\n \"2005-09-30 00:00:00-04:00\",\n \"1996-07-12 00:00:00-04:00\",\n \"2023-11-17 00:00:00-05:00\"\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"Open\",\n \"properties\": {\n \"dtype\": \"number\",\n \"std\": 14.708246895727896,\n \"min\": 0.121967708,\n \"max\": 62.0287604,\n \"num_unique_values\": 10235,\n \"samples\": [\n 0.217799649,\n 38.19956342,\n 12.56713476\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"High\",\n \"properties\": {\n \"dtype\": \"number\",\n \"std\": 14.892642189263558,\n \"min\": 0.121967708,\n \"max\": 62.2925199,\n \"num_unique_values\": 9923,\n \"samples\": [\n 10.52320472,\n 0.421079006,\n 9.364270401\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"Low\",\n \"properties\": {\n \"dtype\": \"number\",\n \"std\": 14.526521042423367,\n \"min\": 0.120515808,\n \"max\": 60.60083325,\n \"num_unique_values\": 9857,\n \"samples\": [\n 39.87258453,\n 0.360095072,\n 55.46208027\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"Close\",\n \"properties\": {\n \"dtype\": \"number\",\n \"std\": 14.709644292423453,\n \"min\": 0.120515808,\n \"max\": 62.08334351,\n \"num_unique_values\": 7999,\n \"samples\": [\n 16.59060097,\n 14.25704384,\n 10.75390244\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"Volume\",\n \"properties\": {\n \"dtype\": \"number\",\n \"std\": 34759456,\n \"min\": 0,\n \"max\": 567708800,\n \"num_unique_values\": 10831,\n \"samples\": [\n 5510400,\n 43139200,\n 59109200\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"Dividends\",\n \"properties\": {\n \"dtype\": \"number\",\n \"std\": 0.019592219401798217,\n \"min\": 0.0,\n \"max\": 0.365,\n \"num_unique_values\": 28,\n \"samples\": [\n 0.04,\n 0.348,\n 0.02\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"Stock Splits\",\n \"properties\": {\n \"dtype\": \"number\",\n \"std\": 0.05174892897105917,\n \"min\": 0.0,\n \"max\": 2.0,\n \"num_unique_values\": 3,\n \"samples\": [\n 0.0,\n 2.0,\n 1.5\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n }\n ]\n}" } }, "metadata": {}, "execution_count": 8 } ] }, { "cell_type": "code", "source": [ "train['Daily Return'] = train['Close'].pct_change() * 100\n", "\n", "train['7-Day MA'] = train['Close'].rolling(window=7).mean()\n", "train['30-Day MA'] = train['Close'].rolling(window=30).mean()\n", "\n", "train.head(10)" ], "metadata": { "colab": { "base_uri": "https://localhost:8080/", "height": 970 }, "id": "IXVP_Ccj0ShM", "outputId": "23b45855-d9b4-4ac4-85b7-cb9e5c4a797a" }, "execution_count": 9, "outputs": [ { "output_type": "execute_result", "data": { "text/plain": [ " Open High Low Close Volume \\\n", "Date \n", "1980-03-17 00:00:00-05:00 0.181500 0.184404 0.181500 0.181500 10924800 \n", "1980-03-18 00:00:00-05:00 0.181500 0.182952 0.180048 0.180048 17068800 \n", "1980-03-19 00:00:00-05:00 0.184404 0.187308 0.184404 0.184404 18508800 \n", "1980-03-20 00:00:00-05:00 0.184403 0.186581 0.183678 0.183678 11174400 \n", "1980-03-21 00:00:00-05:00 0.180048 0.180048 0.177143 0.177143 12172800 \n", "1980-03-24 00:00:00-05:00 0.176417 0.176417 0.173514 0.173514 8966400 \n", "1980-03-25 00:00:00-05:00 0.174240 0.177144 0.174240 0.174240 11347200 \n", "1980-03-26 00:00:00-05:00 0.174240 0.175692 0.172788 0.172788 16262400 \n", "1980-03-27 00:00:00-05:00 0.169884 0.169884 0.166980 0.166980 26918400 \n", "1980-03-28 00:00:00-05:00 0.173514 0.176417 0.173514 0.173514 20102400 \n", "\n", " Dividends Stock Splits Daily Return 7-Day MA \\\n", "Date \n", "1980-03-17 00:00:00-05:00 0.0 0.0 NaN NaN \n", "1980-03-18 00:00:00-05:00 0.0 0.0 -0.799935 NaN \n", "1980-03-19 00:00:00-05:00 0.0 0.0 2.419199 NaN \n", "1980-03-20 00:00:00-05:00 0.0 0.0 -0.393694 NaN \n", "1980-03-21 00:00:00-05:00 0.0 0.0 -3.557432 NaN \n", "1980-03-24 00:00:00-05:00 0.0 0.0 -2.049001 NaN \n", "1980-03-25 00:00:00-05:00 0.0 0.0 0.418462 0.179218 \n", "1980-03-26 00:00:00-05:00 0.0 0.0 -0.833300 0.177973 \n", "1980-03-27 00:00:00-05:00 0.0 0.0 -3.361440 0.176106 \n", "1980-03-28 00:00:00-05:00 0.0 0.0 3.913058 0.174551 \n", "\n", " 30-Day MA \n", "Date \n", "1980-03-17 00:00:00-05:00 NaN \n", "1980-03-18 00:00:00-05:00 NaN \n", "1980-03-19 00:00:00-05:00 NaN \n", "1980-03-20 00:00:00-05:00 NaN \n", "1980-03-21 00:00:00-05:00 NaN \n", "1980-03-24 00:00:00-05:00 NaN \n", "1980-03-25 00:00:00-05:00 NaN \n", "1980-03-26 00:00:00-05:00 NaN \n", "1980-03-27 00:00:00-05:00 NaN \n", "1980-03-28 00:00:00-05:00 NaN " ], "text/html": [ "\n", "
\n", "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
OpenHighLowCloseVolumeDividendsStock SplitsDaily Return7-Day MA30-Day MA
Date
1980-03-17 00:00:00-05:000.1815000.1844040.1815000.181500109248000.00.0NaNNaNNaN
1980-03-18 00:00:00-05:000.1815000.1829520.1800480.180048170688000.00.0-0.799935NaNNaN
1980-03-19 00:00:00-05:000.1844040.1873080.1844040.184404185088000.00.02.419199NaNNaN
1980-03-20 00:00:00-05:000.1844030.1865810.1836780.183678111744000.00.0-0.393694NaNNaN
1980-03-21 00:00:00-05:000.1800480.1800480.1771430.177143121728000.00.0-3.557432NaNNaN
1980-03-24 00:00:00-05:000.1764170.1764170.1735140.17351489664000.00.0-2.049001NaNNaN
1980-03-25 00:00:00-05:000.1742400.1771440.1742400.174240113472000.00.00.4184620.179218NaN
1980-03-26 00:00:00-05:000.1742400.1756920.1727880.172788162624000.00.0-0.8333000.177973NaN
1980-03-27 00:00:00-05:000.1698840.1698840.1669800.166980269184000.00.0-3.3614400.176106NaN
1980-03-28 00:00:00-05:000.1735140.1764170.1735140.173514201024000.00.03.9130580.174551NaN
\n", "
\n", "
\n", "\n", "
\n", " \n", "\n", " \n", "\n", " \n", "
\n", "\n", "\n", "
\n", " \n", "\n", "\n", "\n", " \n", "
\n", "\n", "
\n", "
\n" ], "application/vnd.google.colaboratory.intrinsic+json": { "type": "dataframe", "variable_name": "train", "summary": "{\n \"name\": \"train\",\n \"rows\": 11289,\n \"fields\": [\n {\n \"column\": \"Date\",\n \"properties\": {\n \"dtype\": \"string\",\n \"num_unique_values\": 11289,\n \"samples\": [\n \"2005-09-30 00:00:00-04:00\",\n \"1996-07-12 00:00:00-04:00\",\n \"2023-11-17 00:00:00-05:00\"\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"Open\",\n \"properties\": {\n \"dtype\": \"number\",\n \"std\": 14.708246895727896,\n \"min\": 0.121967708,\n \"max\": 62.0287604,\n \"num_unique_values\": 10235,\n \"samples\": [\n 0.217799649,\n 38.19956342,\n 12.56713476\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"High\",\n \"properties\": {\n \"dtype\": \"number\",\n \"std\": 14.892642189263558,\n \"min\": 0.121967708,\n \"max\": 62.2925199,\n \"num_unique_values\": 9923,\n \"samples\": [\n 10.52320472,\n 0.421079006,\n 9.364270401\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"Low\",\n \"properties\": {\n \"dtype\": \"number\",\n \"std\": 14.526521042423367,\n \"min\": 0.120515808,\n \"max\": 60.60083325,\n \"num_unique_values\": 9857,\n \"samples\": [\n 39.87258453,\n 0.360095072,\n 55.46208027\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"Close\",\n \"properties\": {\n \"dtype\": \"number\",\n \"std\": 14.709644292423453,\n \"min\": 0.120515808,\n \"max\": 62.08334351,\n \"num_unique_values\": 7999,\n \"samples\": [\n 16.59060097,\n 14.25704384,\n 10.75390244\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"Volume\",\n \"properties\": {\n \"dtype\": \"number\",\n \"std\": 34759456,\n \"min\": 0,\n \"max\": 567708800,\n \"num_unique_values\": 10831,\n \"samples\": [\n 5510400,\n 43139200,\n 59109200\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"Dividends\",\n \"properties\": {\n \"dtype\": \"number\",\n \"std\": 0.019592219401798217,\n \"min\": 0.0,\n \"max\": 0.365,\n \"num_unique_values\": 28,\n \"samples\": [\n 0.04,\n 0.348,\n 0.02\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"Stock Splits\",\n \"properties\": {\n \"dtype\": \"number\",\n \"std\": 0.05174892897105917,\n \"min\": 0.0,\n \"max\": 2.0,\n \"num_unique_values\": 3,\n \"samples\": [\n 0.0,\n 2.0,\n 1.5\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"Daily Return\",\n \"properties\": {\n \"dtype\": \"number\",\n \"std\": 2.5226338717913688,\n \"min\": -26.058514561573208,\n \"max\": 26.378041994468603,\n \"num_unique_values\": 10286,\n \"samples\": [\n 0.3757846127687037,\n 0.356730448388376,\n 0.6518626795502858\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"7-Day MA\",\n \"properties\": {\n \"dtype\": \"number\",\n \"std\": 14.70227910815849,\n \"min\": 0.12321235228571428,\n \"max\": 60.32537950857142,\n \"num_unique_values\": 11140,\n \"samples\": [\n 13.281238692857144,\n 0.14416258457142855,\n 18.49832316857143\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"30-Day MA\",\n \"properties\": {\n \"dtype\": \"number\",\n \"std\": 14.679627491429843,\n \"min\": 0.13416450253333334,\n \"max\": 58.625973384,\n \"num_unique_values\": 11221,\n \"samples\": [\n 42.51594085766667,\n 45.744107183,\n 12.367740472333333\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n }\n ]\n}" } }, "metadata": {}, "execution_count": 9 } ] }, { "cell_type": "code", "source": [ "train['7-Day MA'] = train['7-Day MA'].fillna(method='ffill').fillna(method='bfill')\n", "train['30-Day MA'] = train['30-Day MA'].fillna(method='ffill').fillna(method='bfill')\n", "\n", "train['Daily Return'] = train['Daily Return'].fillna(0)\n", "\n", "missing_values_after = train.isnull().sum()\n", "missing_values_after" ], "metadata": { "colab": { "base_uri": "https://localhost:8080/", "height": 487 }, "id": "eCdosU1p0mDO", "outputId": "fa1d433b-24e5-4ed4-b94c-dade52723dd8" }, "execution_count": 10, "outputs": [ { "output_type": "stream", "name": "stderr", "text": [ ":1: FutureWarning: Series.fillna with 'method' is deprecated and will raise in a future version. Use obj.ffill() or obj.bfill() instead.\n", " train['7-Day MA'] = train['7-Day MA'].fillna(method='ffill').fillna(method='bfill')\n", ":2: FutureWarning: Series.fillna with 'method' is deprecated and will raise in a future version. Use obj.ffill() or obj.bfill() instead.\n", " train['30-Day MA'] = train['30-Day MA'].fillna(method='ffill').fillna(method='bfill')\n" ] }, { "output_type": "execute_result", "data": { "text/plain": [ "Open 0\n", "High 0\n", "Low 0\n", "Close 0\n", "Volume 0\n", "Dividends 0\n", "Stock Splits 0\n", "Daily Return 0\n", "7-Day MA 0\n", "30-Day MA 0\n", "dtype: int64" ], "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
0
Open0
High0
Low0
Close0
Volume0
Dividends0
Stock Splits0
Daily Return0
7-Day MA0
30-Day MA0
\n", "

" ] }, "metadata": {}, "execution_count": 10 } ] } ] }