This repository was archived by the owner on Sep 6, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconvert_gprn_to_X.py
More file actions
51 lines (36 loc) · 1.5 KB
/
convert_gprn_to_X.py
File metadata and controls
51 lines (36 loc) · 1.5 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
46
47
48
49
50
51
from cost_table import cost_table_gas
import pandas as pd
import pathlib
# + tags=["parameters"]
upstream = None
product = {"nb": "output/gprn2primary.ipynb", "data": "output/gprn_tper_2020.csv"}
# -
inpath = pathlib.Path("data/SDCC - GPRN Consumption (2020)-V1.csv")
##Conversion Factors
total_final_consumption_to_total_primary_requirement = 1.1
total_final_consumption_to_co2 = 0.2047
year = "2020"
read_from_row = 24
def drop_commas_in_numeric_columns(s: pd.Series) -> pd.Series:
return s.str.replace(",", "")
index_columns = ["GPRN", "SiteID", "Division"]
columns_to_drop = ["Location", "Unit"]
gprn_raw = pd.read_csv(inpath, header=read_from_row)
assert set(index_columns).issubset(
gprn_raw.columns
), f"{index_columns} not in the dataset"
assert set(columns_to_drop).issubset(gprn_raw.columns)
gprn = (
gprn_raw.set_index(index_columns)
.drop(columns=columns_to_drop)
.apply(drop_commas_in_numeric_columns, axis="columns")
.astype("float64")
) #* total_final_consumption_to_total_primary_requirement
gprn_recent = pd.DataFrame(gprn.iloc[:, 0])
gprn_recent.columns = ['TFC(kwh)']
gprn_recent['TPER(kwh)'] = gprn_recent['TFC(kwh)'] * total_final_consumption_to_total_primary_requirement
gprn_recent['CO2(kg)'] = gprn_recent['TFC(kwh)'] * total_final_consumption_to_co2
gprn_recent['Cost (Euro/kwh)'] = gprn_recent['TFC(kwh)'].apply(cost_table_gas)#, axis = 'columns')
gprn_recent['Euro'] = gprn_recent['TFC(kwh)'] * gprn_recent['Cost (Euro/kwh)']
gprn_recent
#gprn[year].to_csv(product["data"])