-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnormalize.py
More file actions
28 lines (19 loc) · 806 Bytes
/
normalize.py
File metadata and controls
28 lines (19 loc) · 806 Bytes
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
import pandas as pd
import os
def normalize_df(df):
n_df = df.copy()
n_df.rename({"This week": "This_Week", "Last Week": "Last_Week", "Last Year": "Last_Year"}, axis=1, inplace=True)
# this columns are all percentages
n_df["This_Week"] /= 100.0
n_df["Last_Week"] /= 100.0
n_df["Last_Year"] /= 100.0
fsc_max = n_df["FSC"].max()
fsc_min = n_df["FSC"].min()
# squish the full storage capacity values between 0.1 and 0.9
n_df["FSC"] = 0.1 + (n_df["FSC"] - fsc_min) * 0.8 / (fsc_max - fsc_min)
return n_df
def get_norm_csv(path):
old_csv = os.path.abspath(path)
new_csv = os.path.join(os.path.dirname(old_csv), "norm_" + os.path.basename(old_csv))
n_df = normalize_df(pd.read_csv(old_csv, sep=','))
n_df.to_csv(new_csv, sep=',', index=False)