File size: 1,760 Bytes
8be024f |
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 46 47 48 49 50 51 52 53 54 55 56 57 58 |
import csv
from pathlib import Path
import numpy as np
import pandas as pd
from collections import defaultdict
FULL_DATA_SET_STRING = "../full_2023_remove_flawed_rows.csv"
FULL_DATA_SET_PATH = Path(FULL_DATA_SET_STRING)
OUT_DATASET_STRING = "../zscore_2023.parquet"
OUT_DATASET_PATH = Path(OUT_DATASET_STRING)
OUT_FULL_DATASET_STRING = "../full_2023_remove_flawed.parquet"
OUT_FULL_DATASET_PATH = Path(OUT_FULL_DATASET_STRING)
NUMERIC_FIELDS = ["WSPD","GST","WVHT","DPD","APD","PRES","ATMP","WTMP"]
def load_data(data_path):
print("Loading data")
with open(data_path, newline='') as csv_file:
loaded_np_data = pd.read_csv(csv_file)
print("Writing out the full Parquet file")
loaded_np_data.to_parquet(OUT_FULL_DATASET_PATH)
print("Applying Sin() to the two degrees columns")
loaded_np_data["WDIR"] = np.sin(np.deg2rad(loaded_np_data["WDIR"]))
loaded_np_data["MWD"] = np.sin(np.deg2rad(loaded_np_data["MWD"]))
print("calculating z-scores")
for var in NUMERIC_FIELDS:
var_mean = np.mean(loaded_np_data[var])
var_std = np.std(loaded_np_data[var])
var_zscore = (loaded_np_data[var] - var_mean)/var_std
loaded_np_data[var] = var_zscore
print("exporting to parquet")
loaded_np_data.set_index("TSTMP")
loaded_np_data.to_parquet(OUT_DATASET_PATH)
if __name__ == '__main__':
print("Start")
# Load data
all_data = load_data(FULL_DATA_SET_PATH)
# Calculate mean and std dev for each non-date column
# Going to need to sin(X) for any circular numbers (WDIR & MWD)
# Write out data removing rows
# Probably want to write out the sin(X) for any circular numbers
print("finished") |