-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgetData.py
More file actions
45 lines (36 loc) · 1.37 KB
/
Copy pathgetData.py
File metadata and controls
45 lines (36 loc) · 1.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import pandas as pd
import os
import time
import quandl
quandl.ApiConfig.api_key = "KNMsE79xmVujz6W5CHub"
path = r"C:\Users\jvgcu\Desktop\Python4Investiments\intraQuarter"
def Stock_Prices():
df = pd.DataFrame()
statspath = path + "/_KeyStats"
stock_list = [x[0] for x in os.walk(statspath)]
for each_dir in stock_list[1:]:
try:
ticker = each_dir.split("\\")[-1]
print(ticker)
name = "WIKI/" + ticker.upper()
data = quandl.get(name, trim_start="2000-12-12", trim_end="2019-12-30")
data[ticker.upper()] = data["Adj. Close"]
df = pd.concat([df, data[ticker.upper()]], axis=1)
except Exception as e1:
print("E1: ", str(e1))
time.sleep(2)
try:
ticker = each_dir.split("\\")[-1]
print(ticker)
name = "WIKI/" + ticker.upper()
data = quandl.get(name, trim_start="2000-12-12", trim_end="2019-12-30")
data[ticker.upper()] = data["Adj. Close"]
df = pd.concat([df, data[ticker.upper()]], axis=1)
except Exception as e2:
print("E2: ", str(e2))
df.index.rename("Date", inplace=True)
df.reset_index(inplace=True)
df["Date"] = pd.to_datetime(df["Date"])
df.to_csv("stock_prices.csv", index=False)
return df
df = Stock_Prices()