{ "cells": [ { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "import pandas as pd" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [], "source": [ "df_apple = pd.read_csv('../coal-price-data/investing/AAPL Historical Data.csv')\n", "df_walmart = pd.read_csv('../coal-price-data/investing/WMT Historical Data.csv')\n", "df_tesla = pd.read_csv('../coal-price-data/investing/TSLA Historical Data.csv')" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
DatePriceOpenHighLowVol.Change %
002/01/2024182.52183.97191.00179.2645.12M-1.02%
101/01/2024184.40187.15196.38180.171.19B-4.22%
212/01/2023192.53190.33199.62187.451.06B1.36%
311/01/2023189.95171.00192.93170.121.10B11.23%
410/01/2023170.77171.22182.34165.671.17B-0.26%
........................
51305/01/19810.150.130.150.12590.42M15.38%
51404/01/19810.130.110.130.11536.93M18.18%
51503/01/19810.110.120.120.10700.72M-8.33%
51602/01/19810.120.120.130.11321.62M-7.69%
51701/01/19810.130.150.160.13608.99M-13.33%
\n", "

518 rows × 7 columns

\n", "
" ], "text/plain": [ " Date Price Open High Low Vol. Change %\n", "0 02/01/2024 182.52 183.97 191.00 179.26 45.12M -1.02%\n", "1 01/01/2024 184.40 187.15 196.38 180.17 1.19B -4.22%\n", "2 12/01/2023 192.53 190.33 199.62 187.45 1.06B 1.36%\n", "3 11/01/2023 189.95 171.00 192.93 170.12 1.10B 11.23%\n", "4 10/01/2023 170.77 171.22 182.34 165.67 1.17B -0.26%\n", ".. ... ... ... ... ... ... ...\n", "513 05/01/1981 0.15 0.13 0.15 0.12 590.42M 15.38%\n", "514 04/01/1981 0.13 0.11 0.13 0.11 536.93M 18.18%\n", "515 03/01/1981 0.11 0.12 0.12 0.10 700.72M -8.33%\n", "516 02/01/1981 0.12 0.12 0.13 0.11 321.62M -7.69%\n", "517 01/01/1981 0.13 0.15 0.16 0.13 608.99M -13.33%\n", "\n", "[518 rows x 7 columns]" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df_apple" ] }, { "cell_type": "code", "execution_count": 13, "metadata": {}, "outputs": [], "source": [ "df = pd.merge(df_apple[['Date', 'Price']], df_walmart[['Date', 'Price']], on='Date', how='right').rename(columns = {'Adj Close_x':'apple', 'Adj Close_y':'walmart'})\n", "df = df.merge(df_tesla[['Date', 'Price']], on='Date', how='right').rename(columns={'Adj Close':'tesla'})" ] }, { "cell_type": "code", "execution_count": 14, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
DatePrice_xPrice_yPrice
002/01/2024182.52175.56191.97
101/01/2024184.40165.25187.29
212/01/2023192.53157.65248.48
311/01/2023189.95155.69240.08
410/01/2023170.77163.41200.84
...............
15911/01/201011.1154.092.36
16010/01/201010.7554.171.46
16109/01/201010.1353.521.36
16208/01/20108.6850.141.30
16307/01/20109.1951.191.33
\n", "

164 rows × 4 columns

\n", "
" ], "text/plain": [ " Date Price_x Price_y Price\n", "0 02/01/2024 182.52 175.56 191.97\n", "1 01/01/2024 184.40 165.25 187.29\n", "2 12/01/2023 192.53 157.65 248.48\n", "3 11/01/2023 189.95 155.69 240.08\n", "4 10/01/2023 170.77 163.41 200.84\n", ".. ... ... ... ...\n", "159 11/01/2010 11.11 54.09 2.36\n", "160 10/01/2010 10.75 54.17 1.46\n", "161 09/01/2010 10.13 53.52 1.36\n", "162 08/01/2010 8.68 50.14 1.30\n", "163 07/01/2010 9.19 51.19 1.33\n", "\n", "[164 rows x 4 columns]" ] }, "execution_count": 14, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df" ] }, { "cell_type": "code", "execution_count": 15, "metadata": {}, "outputs": [], "source": [ "df['Date'] = pd.to_datetime(df['Date'])" ] }, { "cell_type": "code", "execution_count": 16, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
DatePrice_xPrice_yPrice
02024-02-01182.52175.56191.97
12024-01-01184.40165.25187.29
22023-12-01192.53157.65248.48
32023-11-01189.95155.69240.08
42023-10-01170.77163.41200.84
...............
1592010-11-0111.1154.092.36
1602010-10-0110.7554.171.46
1612010-09-0110.1353.521.36
1622010-08-018.6850.141.30
1632010-07-019.1951.191.33
\n", "

164 rows × 4 columns

\n", "
" ], "text/plain": [ " Date Price_x Price_y Price\n", "0 2024-02-01 182.52 175.56 191.97\n", "1 2024-01-01 184.40 165.25 187.29\n", "2 2023-12-01 192.53 157.65 248.48\n", "3 2023-11-01 189.95 155.69 240.08\n", "4 2023-10-01 170.77 163.41 200.84\n", ".. ... ... ... ...\n", "159 2010-11-01 11.11 54.09 2.36\n", "160 2010-10-01 10.75 54.17 1.46\n", "161 2010-09-01 10.13 53.52 1.36\n", "162 2010-08-01 8.68 50.14 1.30\n", "163 2010-07-01 9.19 51.19 1.33\n", "\n", "[164 rows x 4 columns]" ] }, "execution_count": 16, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df" ] }, { "cell_type": "code", "execution_count": 17, "metadata": {}, "outputs": [], "source": [ "df = df.set_index('Date').rename_axis('company', axis=1)" ] }, { "cell_type": "code", "execution_count": 18, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
companyPrice_xPrice_yPrice
Date
2024-02-01182.52175.56191.97
2024-01-01184.40165.25187.29
2023-12-01192.53157.65248.48
2023-11-01189.95155.69240.08
2023-10-01170.77163.41200.84
............
2010-11-0111.1154.092.36
2010-10-0110.7554.171.46
2010-09-0110.1353.521.36
2010-08-018.6850.141.30
2010-07-019.1951.191.33
\n", "

164 rows × 3 columns

\n", "
" ], "text/plain": [ "company Price_x Price_y Price\n", "Date \n", "2024-02-01 182.52 175.56 191.97\n", "2024-01-01 184.40 165.25 187.29\n", "2023-12-01 192.53 157.65 248.48\n", "2023-11-01 189.95 155.69 240.08\n", "2023-10-01 170.77 163.41 200.84\n", "... ... ... ...\n", "2010-11-01 11.11 54.09 2.36\n", "2010-10-01 10.75 54.17 1.46\n", "2010-09-01 10.13 53.52 1.36\n", "2010-08-01 8.68 50.14 1.30\n", "2010-07-01 9.19 51.19 1.33\n", "\n", "[164 rows x 3 columns]" ] }, "execution_count": 18, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "py311-kfp240-airflow251", "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.12.1" } }, "nbformat": 4, "nbformat_minor": 2 }