Repository for Petra's work at ampli Jan-Feb 2019

downkwh.py 996B

123456789101112131415161718192021222324252627282930313233
  1. from util import getQuery, pickleQuery, getkwh
  2. import pandas as p
  3. import gc
  4. from datetime import datetime
  5. from tqdm import tqdm
  6. months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
  7. mstarts = list(range(1, 13))
  8. mends = mstarts[1:13]
  9. mends.append(1)
  10. yends = [2017] * 11
  11. yends.append(2018)
  12. for i, m in tqdm(enumerate(months)):
  13. # if i < 11:
  14. # continue
  15. print(m)
  16. print(datetime.now().time())
  17. kwhdata = getkwh('2017-{:02d}-01'.format(mstarts[i]),
  18. '{}-{:02d}-01'.format(yends[i], mends[i]),
  19. '2017-{:02d}-01 00:30:00'.format(mstarts[i]),
  20. '{}-{:02d}-01 00:00:00'.format(yends[i], mends[i]),
  21. '%%1')
  22. print("Pivoting")
  23. kwhpiv = kwhdata.pivot(index = 'read_time', columns = 'icp_id', values = 'kwh_tot')
  24. print("Pickling")
  25. kwhpiv.to_pickle('../data/2017-{}-5k.pkl'.format(m))
  26. del kwhdata
  27. del kwhpiv
  28. gc.collect()
  29. print('Done')