BatteRaquette58 commited on
Commit
7900bad
1 Parent(s): cfa54cb

Upload 2 files

Browse files
Files changed (1) hide show
  1. generate_dataset.py +13 -23
generate_dataset.py CHANGED
@@ -18,7 +18,8 @@ from huggingface_hub import HfApi
18
 
19
  # load original datasets
20
  stock_price = array(load_dataset("nateraw/airbnb-stock-price")["train"])
21
- stock_price_2 = array(load_dataset("nateraw/airbnb-stock-price-new-new-new")["train"])
 
22
 
23
  def convert_to_timestamp(date: str) -> float:
24
  "Converts different date format strings from the datasets into a timestamp."
@@ -40,28 +41,17 @@ def data_generator():
40
 
41
  dates = [] # to not have duplicate dates
42
 
43
- for price in stock_price:
44
- row = {}
45
- row["date"] = convert_to_timestamp(price["Date"])
46
- dates.append(row["date"])
47
- row["open"] = price["Open"]
48
- row["close_last"] = price["Adj.Close"]
49
- row["volume"] = price["Volume"]
50
- row["high"] = price["High"]
51
- row["low"] = price["Low"]
52
- yield row
53
-
54
- for price in stock_price_2:
55
- row = {}
56
- row["date"] = convert_to_timestamp(price["date"])
57
- if row["date"] in dates:
58
- continue # prevent having duplicate dates
59
- row["open"] = price["open"]
60
- row["close_last"] = price["close_last"]
61
- row["volume"] = price["volume"]
62
- row["high"] = price["high"]
63
- row["low"] = price["low"]
64
- yield row
65
 
66
  # generate dataset object, export them, and push to hub
67
  dataset = Dataset.from_generator(data_generator)
 
18
 
19
  # load original datasets
20
  stock_price = array(load_dataset("nateraw/airbnb-stock-price")["train"])
21
+ stock_price_2 = array(load_dataset("nateraw/airbnb-stock-price-2")["train"])
22
+ datasets = (stock_price, stock_price_2)
23
 
24
  def convert_to_timestamp(date: str) -> float:
25
  "Converts different date format strings from the datasets into a timestamp."
 
41
 
42
  dates = [] # to not have duplicate dates
43
 
44
+ for stock in datasets:
45
+ for price in stock:
46
+ row = {}
47
+ row["date"] = convert_to_timestamp(price["Date"] if "Date" in price else price["open"])
48
+ dates.append(row["date"])
49
+ row["open"] = price["Open"] if "Open" in price else price["open"]
50
+ row["close_last"] = price["Adj.Close"] if "Adj.Close" in price else price["open"]
51
+ row["volume"] = price["Volume"] if "Volume" in price else price["open"]
52
+ row["high"] = price["High"] if "High" in price else price["open"]
53
+ row["low"] = price["Low"] if "Low" in price else price["open"]
54
+ yield row
 
 
 
 
 
 
 
 
 
 
 
55
 
56
  # generate dataset object, export them, and push to hub
57
  dataset = Dataset.from_generator(data_generator)