-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhelperFunctions.py
62 lines (56 loc) · 1.91 KB
/
helperFunctions.py
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
59
60
61
62
# helper functions
import pandas as pd
from datetime import datetime
import numpy as np
#%% CONVERTING DATA FROM STRING TO DATETIME INDEX
# input: data
# output: data
def ind(data):
time = []
# for each index/row
for i in range(len(data.index)):
# reading index
t = data.index[i]
# splitting day and hour
day, hour = t.split(' ')
#
timestamp = datetime.strptime(t, "%Y/%m/%d %H:%M:%S")
#
time.append(timestamp)
#
data.index = pd.to_datetime(time)
return data
#%% CONVERTING DATA TO FLOAT
# input: data
# output: data
def fl(data):
# retrieving data columns
cols = data.columns
# for each columns
for col in cols:
# converting to float
data[col] = data[col].astype(float)
return data
#%% FITTING MISSING DATA
# input parameters: time series
# output parameters: fitted time series
def fitData(df):
# fitting with zero, can also be done differently
for i in np.arange(1,len(df.total_power) - 1):
d1 = df.index[i]
d2 = df.index[i+1]
diff = d2.hour - d1.hour
# EXPLORATION of the values we could have
#print(diff)
# if there is no missing values, go on
if ((diff == 1) | (diff == -22) | (diff == 0)):
pass
# if there is a missing value
else:
# EXPLORATION
#print("Inserting missing value")
# to check if the initial and final size of df are given by missing hours
for j in np.arange(diff):
new = d1.replace(hour=d1.hour+j).strftime("%Y-%m-%d %H:%M:%S")
df = df.append({'index':new,'total_power':df.total_power.mean(),'t_in':df.t_in.mean(),'t_out':df.t_out.mean(),'temp_diff':df.temp_diff.mean(),'power_heating':df.power_heating.mean(),'power_cooling':df.power_cooling.mean(),'power_electricity':df.power_electricity.mean()},ignore_index=True)
return df