Browse Source

Download and collate in wide form, month-by-month

Petra Lamborn 5 years ago
parent
commit
396cad8454
2 changed files with 25 additions and 6 deletions
  1. 19
    0
      py/collate.py
  2. 6
    6
      py/downkwh.py

+ 19
- 0
py/collate.py View File

@@ -0,0 +1,19 @@
1
+# Collate 12 dataframes into one (wide) combined dataframe
2
+import pandas as p
3
+import gc
4
+
5
+
6
+months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
7
+
8
+coldf = p.read_pickle('../data/2017-{}-all.pkl'.format(months[0]))
9
+
10
+for i in range(1, 12):
11
+    tdf = p.read_pickle('../data/2017-{}-all.pkl'.format(months[i])) 
12
+    coldf = p.concat([coldf, tdf])
13
+    del tdf
14
+    gc.collect()
15
+
16
+print(coldf.info())
17
+
18
+coldf.to_pickle('../data/2017-all-wide.pkl')
19
+

+ 6
- 6
py/downkwh.py View File

@@ -7,19 +7,19 @@ months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct',
7 7
 mstarts = list(range(1, 13))
8 8
 mends = mstarts[1:13]
9 9
 mends.append(1)
10
-
11
-print(months)
12
-print(mstarts)
13
-print(mends)
10
+yends = [2017] * 11
11
+yends.append(2018)
14 12
 
15 13
 for i, m in enumerate(months):
14
+    if i < 11:
15
+        continue
16 16
     print(i)
17 17
     print(m)
18 18
     print(datetime.now().time())
19 19
     kwhdata = getkwh('2017-{:02d}-01'.format(mstarts[i]), 
20
-                     '2017-{:02d}-01'.format(mends[i]), 
20
+                     '{}-{:02d}-01'.format(yends[i], mends[i]), 
21 21
                      '2017-{:02d}-01 00:30:00'.format(mstarts[i]), 
22
-                     '2017-{:02d}-01 00:00:00'.format(mends[i]), 
22
+                     '{}-{:02d}-01 00:00:00'.format(yends[i], mends[i]), 
23 23
                      '%%1')
24 24
     print("Pivoting")
25 25
     kwhpiv = kwhdata.pivot(index = 'read_time', columns = 'icp_id', values = 'kwh_tot')