-
Notifications
You must be signed in to change notification settings - Fork 0
/
plotly_rolling.py
85 lines (66 loc) · 1.94 KB
/
plotly_rolling.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import plotly
import plotly.graph_objs as go
import numpy as np
import numpy as np
import pandas as pd
import seaborn as sns
import matplotlib
import matplotlib.pyplot as plt
def str2float(x):
return float(x.replace(',', '.'))
df = pd.read_csv("data/hackathon_EnBW_smart_meter_data_30_hh.csv", sep=';', na_values=['NA'],
converters={'value': str2float})
df['timestampLocal'] = pd.to_datetime(df.timestampLocal)
# print(df.isnull().sum())
# print(df[df.timestampLocal.isnull()])
grouped = df.groupby("id")
data_list = []
for n, g in grouped:
id = g['id'].iloc[0]
# print(id)
g = g.set_index('timestampLocal')
g = g.resample("4h").sum()
g['rolling_4'] = g['value'].rolling(window=4).mean()
g['std_12'] = g['value'].rolling(window=20, center=True).std()
# print(g)
g['index'] = range(1, len(g) + 1)
print(g)
g.set_index('index')
graph_data = go.Scatter(
x=g['index'].values,
# x = g['timestampLocal'],
y=g['value'].values,
name='Haushalt' + str(id),
line=dict(
color=('blue'),
width=2)
)
graph_data_rolling = go.Scatter(
x=g['index'].values,
# x = g['timestampLocal'],
y=g['rolling_4'].values,
name='Haushalt rolling' + str(id),
line=dict(
color=('red'),
width=2)
)
graph_data_std = go.Scatter(
x=g['index'].values,
# x = g['timestampLocal'],
y=g['std_12'].values,
name='Haushalt rolling' + str(id),
line=dict(
color=('black'),
width=2)
)
data_list.append(graph_data)
layout = dict(
xaxis=dict(title='Date-Time'),
yaxis=dict(title='Watt'),
showlegend=True,
)
data = [graph_data_rolling, graph_data_std]
if id == 9:
fig = dict(data=data, layout=layout)
plotly.offline.plot(fig, auto_open=True, include_plotlyjs=True)
break;