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
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"cells": [
|
3 |
+
{
|
4 |
+
"cell_type": "code",
|
5 |
+
"execution_count": 2,
|
6 |
+
"metadata": {},
|
7 |
+
"outputs": [],
|
8 |
+
"source": [
|
9 |
+
"import pandas as pd"
|
10 |
+
]
|
11 |
+
},
|
12 |
+
{
|
13 |
+
"cell_type": "code",
|
14 |
+
"execution_count": 6,
|
15 |
+
"metadata": {},
|
16 |
+
"outputs": [],
|
17 |
+
"source": [
|
18 |
+
"df_apple = pd.read_csv('../coal-price-data/investing/AAPL Historical Data.csv')\n",
|
19 |
+
"df_walmart = pd.read_csv('../coal-price-data/investing/WMT Historical Data.csv')\n",
|
20 |
+
"df_tesla = pd.read_csv('../coal-price-data/investing/TSLA Historical Data.csv')"
|
21 |
+
]
|
22 |
+
},
|
23 |
+
{
|
24 |
+
"cell_type": "code",
|
25 |
+
"execution_count": 7,
|
26 |
+
"metadata": {},
|
27 |
+
"outputs": [
|
28 |
+
{
|
29 |
+
"data": {
|
30 |
+
"text/html": [
|
31 |
+
"<div>\n",
|
32 |
+
"<style scoped>\n",
|
33 |
+
" .dataframe tbody tr th:only-of-type {\n",
|
34 |
+
" vertical-align: middle;\n",
|
35 |
+
" }\n",
|
36 |
+
"\n",
|
37 |
+
" .dataframe tbody tr th {\n",
|
38 |
+
" vertical-align: top;\n",
|
39 |
+
" }\n",
|
40 |
+
"\n",
|
41 |
+
" .dataframe thead th {\n",
|
42 |
+
" text-align: right;\n",
|
43 |
+
" }\n",
|
44 |
+
"</style>\n",
|
45 |
+
"<table border=\"1\" class=\"dataframe\">\n",
|
46 |
+
" <thead>\n",
|
47 |
+
" <tr style=\"text-align: right;\">\n",
|
48 |
+
" <th></th>\n",
|
49 |
+
" <th>Date</th>\n",
|
50 |
+
" <th>Price</th>\n",
|
51 |
+
" <th>Open</th>\n",
|
52 |
+
" <th>High</th>\n",
|
53 |
+
" <th>Low</th>\n",
|
54 |
+
" <th>Vol.</th>\n",
|
55 |
+
" <th>Change %</th>\n",
|
56 |
+
" </tr>\n",
|
57 |
+
" </thead>\n",
|
58 |
+
" <tbody>\n",
|
59 |
+
" <tr>\n",
|
60 |
+
" <th>0</th>\n",
|
61 |
+
" <td>02/01/2024</td>\n",
|
62 |
+
" <td>182.52</td>\n",
|
63 |
+
" <td>183.97</td>\n",
|
64 |
+
" <td>191.00</td>\n",
|
65 |
+
" <td>179.26</td>\n",
|
66 |
+
" <td>45.12M</td>\n",
|
67 |
+
" <td>-1.02%</td>\n",
|
68 |
+
" </tr>\n",
|
69 |
+
" <tr>\n",
|
70 |
+
" <th>1</th>\n",
|
71 |
+
" <td>01/01/2024</td>\n",
|
72 |
+
" <td>184.40</td>\n",
|
73 |
+
" <td>187.15</td>\n",
|
74 |
+
" <td>196.38</td>\n",
|
75 |
+
" <td>180.17</td>\n",
|
76 |
+
" <td>1.19B</td>\n",
|
77 |
+
" <td>-4.22%</td>\n",
|
78 |
+
" </tr>\n",
|
79 |
+
" <tr>\n",
|
80 |
+
" <th>2</th>\n",
|
81 |
+
" <td>12/01/2023</td>\n",
|
82 |
+
" <td>192.53</td>\n",
|
83 |
+
" <td>190.33</td>\n",
|
84 |
+
" <td>199.62</td>\n",
|
85 |
+
" <td>187.45</td>\n",
|
86 |
+
" <td>1.06B</td>\n",
|
87 |
+
" <td>1.36%</td>\n",
|
88 |
+
" </tr>\n",
|
89 |
+
" <tr>\n",
|
90 |
+
" <th>3</th>\n",
|
91 |
+
" <td>11/01/2023</td>\n",
|
92 |
+
" <td>189.95</td>\n",
|
93 |
+
" <td>171.00</td>\n",
|
94 |
+
" <td>192.93</td>\n",
|
95 |
+
" <td>170.12</td>\n",
|
96 |
+
" <td>1.10B</td>\n",
|
97 |
+
" <td>11.23%</td>\n",
|
98 |
+
" </tr>\n",
|
99 |
+
" <tr>\n",
|
100 |
+
" <th>4</th>\n",
|
101 |
+
" <td>10/01/2023</td>\n",
|
102 |
+
" <td>170.77</td>\n",
|
103 |
+
" <td>171.22</td>\n",
|
104 |
+
" <td>182.34</td>\n",
|
105 |
+
" <td>165.67</td>\n",
|
106 |
+
" <td>1.17B</td>\n",
|
107 |
+
" <td>-0.26%</td>\n",
|
108 |
+
" </tr>\n",
|
109 |
+
" <tr>\n",
|
110 |
+
" <th>...</th>\n",
|
111 |
+
" <td>...</td>\n",
|
112 |
+
" <td>...</td>\n",
|
113 |
+
" <td>...</td>\n",
|
114 |
+
" <td>...</td>\n",
|
115 |
+
" <td>...</td>\n",
|
116 |
+
" <td>...</td>\n",
|
117 |
+
" <td>...</td>\n",
|
118 |
+
" </tr>\n",
|
119 |
+
" <tr>\n",
|
120 |
+
" <th>513</th>\n",
|
121 |
+
" <td>05/01/1981</td>\n",
|
122 |
+
" <td>0.15</td>\n",
|
123 |
+
" <td>0.13</td>\n",
|
124 |
+
" <td>0.15</td>\n",
|
125 |
+
" <td>0.12</td>\n",
|
126 |
+
" <td>590.42M</td>\n",
|
127 |
+
" <td>15.38%</td>\n",
|
128 |
+
" </tr>\n",
|
129 |
+
" <tr>\n",
|
130 |
+
" <th>514</th>\n",
|
131 |
+
" <td>04/01/1981</td>\n",
|
132 |
+
" <td>0.13</td>\n",
|
133 |
+
" <td>0.11</td>\n",
|
134 |
+
" <td>0.13</td>\n",
|
135 |
+
" <td>0.11</td>\n",
|
136 |
+
" <td>536.93M</td>\n",
|
137 |
+
" <td>18.18%</td>\n",
|
138 |
+
" </tr>\n",
|
139 |
+
" <tr>\n",
|
140 |
+
" <th>515</th>\n",
|
141 |
+
" <td>03/01/1981</td>\n",
|
142 |
+
" <td>0.11</td>\n",
|
143 |
+
" <td>0.12</td>\n",
|
144 |
+
" <td>0.12</td>\n",
|
145 |
+
" <td>0.10</td>\n",
|
146 |
+
" <td>700.72M</td>\n",
|
147 |
+
" <td>-8.33%</td>\n",
|
148 |
+
" </tr>\n",
|
149 |
+
" <tr>\n",
|
150 |
+
" <th>516</th>\n",
|
151 |
+
" <td>02/01/1981</td>\n",
|
152 |
+
" <td>0.12</td>\n",
|
153 |
+
" <td>0.12</td>\n",
|
154 |
+
" <td>0.13</td>\n",
|
155 |
+
" <td>0.11</td>\n",
|
156 |
+
" <td>321.62M</td>\n",
|
157 |
+
" <td>-7.69%</td>\n",
|
158 |
+
" </tr>\n",
|
159 |
+
" <tr>\n",
|
160 |
+
" <th>517</th>\n",
|
161 |
+
" <td>01/01/1981</td>\n",
|
162 |
+
" <td>0.13</td>\n",
|
163 |
+
" <td>0.15</td>\n",
|
164 |
+
" <td>0.16</td>\n",
|
165 |
+
" <td>0.13</td>\n",
|
166 |
+
" <td>608.99M</td>\n",
|
167 |
+
" <td>-13.33%</td>\n",
|
168 |
+
" </tr>\n",
|
169 |
+
" </tbody>\n",
|
170 |
+
"</table>\n",
|
171 |
+
"<p>518 rows × 7 columns</p>\n",
|
172 |
+
"</div>"
|
173 |
+
],
|
174 |
+
"text/plain": [
|
175 |
+
" Date Price Open High Low Vol. Change %\n",
|
176 |
+
"0 02/01/2024 182.52 183.97 191.00 179.26 45.12M -1.02%\n",
|
177 |
+
"1 01/01/2024 184.40 187.15 196.38 180.17 1.19B -4.22%\n",
|
178 |
+
"2 12/01/2023 192.53 190.33 199.62 187.45 1.06B 1.36%\n",
|
179 |
+
"3 11/01/2023 189.95 171.00 192.93 170.12 1.10B 11.23%\n",
|
180 |
+
"4 10/01/2023 170.77 171.22 182.34 165.67 1.17B -0.26%\n",
|
181 |
+
".. ... ... ... ... ... ... ...\n",
|
182 |
+
"513 05/01/1981 0.15 0.13 0.15 0.12 590.42M 15.38%\n",
|
183 |
+
"514 04/01/1981 0.13 0.11 0.13 0.11 536.93M 18.18%\n",
|
184 |
+
"515 03/01/1981 0.11 0.12 0.12 0.10 700.72M -8.33%\n",
|
185 |
+
"516 02/01/1981 0.12 0.12 0.13 0.11 321.62M -7.69%\n",
|
186 |
+
"517 01/01/1981 0.13 0.15 0.16 0.13 608.99M -13.33%\n",
|
187 |
+
"\n",
|
188 |
+
"[518 rows x 7 columns]"
|
189 |
+
]
|
190 |
+
},
|
191 |
+
"execution_count": 7,
|
192 |
+
"metadata": {},
|
193 |
+
"output_type": "execute_result"
|
194 |
+
}
|
195 |
+
],
|
196 |
+
"source": [
|
197 |
+
"df_apple"
|
198 |
+
]
|
199 |
+
},
|
200 |
+
{
|
201 |
+
"cell_type": "code",
|
202 |
+
"execution_count": null,
|
203 |
+
"metadata": {},
|
204 |
+
"outputs": [],
|
205 |
+
"source": [
|
206 |
+
"df = pd.merge(df_apple[['Date', 'Adj Close']], df_walmart[['Date', 'Adj Close']], on='Date', how='right').rename(columns = {'Adj Close_x':'apple', 'Adj Close_y':'walmart'})\n",
|
207 |
+
"df = df.merge(df_tesla[['Date', 'Adj Close']], on='Date', how='right').rename(columns={'Adj Close':'tesla'})"
|
208 |
+
]
|
209 |
+
}
|
210 |
+
],
|
211 |
+
"metadata": {
|
212 |
+
"kernelspec": {
|
213 |
+
"display_name": "py311-kfp240-airflow251",
|
214 |
+
"language": "python",
|
215 |
+
"name": "python3"
|
216 |
+
},
|
217 |
+
"language_info": {
|
218 |
+
"codemirror_mode": {
|
219 |
+
"name": "ipython",
|
220 |
+
"version": 3
|
221 |
+
},
|
222 |
+
"file_extension": ".py",
|
223 |
+
"mimetype": "text/x-python",
|
224 |
+
"name": "python",
|
225 |
+
"nbconvert_exporter": "python",
|
226 |
+
"pygments_lexer": "ipython3",
|
227 |
+
"version": "3.12.1"
|
228 |
+
}
|
229 |
+
},
|
230 |
+
"nbformat": 4,
|
231 |
+
"nbformat_minor": 2
|
232 |
+
}
|