Issue
I have a data of 3214 households (.csv format
). Each household has unique id
with power usage
readings for every 5 min interval
. The data sample is shown below:
sample_data.csv
datetime,House_id,power_Usage
2018-01-28 00:00:00,105714,409.365
2018-01-28 00:05:00,105714,409.18
2018-01-28 00:10:00,105714,2424.2399
2018-01-28 00:15:00,105714,225.4576
2018-01-28 00:20:00,105714,225.2768
2018-01-28 00:25:00,105714,2382.1309
2018-01-28 00:30:00,105714,410.685
2018-01-28 00:35:00,105714,317.1043
2018-01-28 00:40:00,105714,2486.6849
2018-01-28 00:45:00,105714,225.3672
2018-01-28 00:50:00,105714,224.644
2018-01-28 00:55:00,105714,2432.4368
2018-01-28 01:00:00,105714,317.2316
2018-01-28 01:05:00,105714,316.4678
2018-01-28 01:10:00,105714,2456.6872
2018-01-28 01:15:00,105714,192.4938
2018-01-28 01:20:00,105714,2471.535
2018-01-28 01:25:00,105714,288.8052
2018-01-28 01:30:00,105714,286.3112
2018-01-28 01:35:00,105714,2403.9675
2018-01-28 01:40:00,105714,282.933
2018-01-28 01:45:00,105714,2465.3581
2018-01-28 01:50:00,105714,289.0368
2018-01-28 01:55:00,105714,194.922
2018-01-28 02:05:00,105714,284.2938
2018-01-28 02:10:00,105714,292.3504
2018-01-28 02:15:00,105714,287.3444
2018-01-28 02:20:00,105714,192.5376
2018-01-28 02:25:00,105714,2347.572
2018-01-28 02:30:00,105714,283.9536
2018-01-28 02:35:00,105714,286.2994
2018-01-28 02:40:00,105714,292.7008
2018-01-28 02:45:00,105714,228.7521
2018-01-28 02:50:00,105714,2292.045
2018-01-28 02:55:00,105714,225.1286
2018-01-28 03:00:00,105714,2458.144
2018-01-28 03:05:00,105714,413.325
2018-01-28 03:10:00,105714,2429.9042
2018-01-28 03:15:00,105714,226.904
2018-01-28 03:20:00,105714,2386.8376
2018-01-28 03:25:00,105714,221.7956
2018-01-28 03:30:00,105714,415.996
2018-01-28 03:35:00,105714,403.627
2018-01-28 03:40:00,105714,314.628
2018-01-28 03:45:00,105714,184.1296
2018-01-28 03:50:00,105714,185.888
2018-01-28 03:55:00,105714,286.482
2018-01-28 04:00:00,105714,363.66
2018-01-28 04:05:00,105714,276.8832
2018-01-28 04:10:00,105714,274.407
2018-01-28 04:15:00,105714,183.8364
2018-01-28 04:20:00,105714,185.518
2018-01-28 04:25:00,105714,277.6936
2018-01-28 04:30:00,105714,276.6624
2018-01-28 04:35:00,105714,273.531
2018-01-28 04:40:00,105714,274.2975
2018-01-28 04:45:00,105714,185.444
2018-01-28 04:50:00,105714,277.25
2018-01-28 04:55:00,105714,185.444
2018-01-28 05:00:00,105714,2435.2544
2018-01-28 05:05:00,105714,273.093
2018-01-28 05:10:00,105714,2360.1338
2018-01-28 05:15:00,105714,281.935
2018-01-28 05:20:00,105714,274.78
2018-01-28 05:25:00,105714,151.5679
2018-01-28 05:30:00,105714,250.1482
2018-01-28 05:35:00,105714,2395.8746
2018-01-28 05:40:00,105714,240.092
2018-01-28 05:45:00,105714,2322.9184
2018-01-28 05:50:00,105714,151.75
2018-01-28 05:55:00,105714,149.5
2018-01-28 06:00:00,105714,268.035
2018-01-28 06:05:00,105714,244.2792
2018-01-28 06:10:00,105714,2475.0576
2018-01-28 06:15:00,105714,153.807
2018-01-28 06:20:00,105714,153.9298
2018-01-28 06:25:00,105714,151.7945
2018-01-28 06:30:00,105714,260.728
2018-01-28 06:35:00,105714,2546.4406
2018-01-28 06:40:00,105714,329.563
2018-01-28 06:45:00,105714,2319.5536
2018-01-28 06:50:00,105714,152.2356
2018-01-28 06:55:00,105714,2225.7051
2018-01-28 07:00:00,105714,294.5414
2018-01-28 07:05:00,105714,2726.5954
2018-01-28 07:10:00,105714,283.4541
2018-01-28 07:15:00,105714,183.1767
2018-01-28 07:20:00,105714,184.704
2018-01-28 07:25:00,105714,2714.9583
2018-01-28 07:30:00,105714,386.8514
2018-01-28 07:35:00,105714,2459.084
2018-01-28 07:40:00,105714,340.5038
2018-01-28 07:45:00,105714,2558.2018
2018-01-28 07:50:00,105714,243.8748
2018-01-28 07:55:00,105714,329.604
2018-01-28 08:00:00,105714,2653.7308
2018-01-28 08:05:00,105714,334.017
2018-01-28 08:10:00,105714,339.177
2018-01-28 08:15:00,105714,2689.1172
2018-01-28 08:20:00,105714,2614.5536
2018-01-28 08:25:00,105714,327.238
2018-01-28 08:30:00,105714,248.2488
2018-01-28 08:35:00,105714,417.2744
2018-01-28 08:40:00,105714,2667.6076
2018-01-28 08:45:00,105714,2583.151
2018-01-28 08:50:00,105714,2674.4692
2018-01-28 08:55:00,105714,2569.8958
2018-01-28 09:00:00,105714,238.3392
2018-01-28 09:05:00,105714,237.5296
2018-01-28 09:10:00,105714,324.7888
2018-01-28 09:15:00,105714,487.674
2018-01-28 09:20:00,105714,325.155
2018-01-28 09:25:00,105714,239.0224
2018-01-28 09:30:00,105714,235.4088
2018-01-28 09:35:00,105714,2540.1132
2018-01-28 09:40:00,105714,2739.0337
2018-01-28 09:45:00,105714,2692.1322
2018-01-28 09:50:00,105714,2586.99
2018-01-28 09:55:00,105714,2537.2891
2018-01-28 10:00:00,105714,2591.6432
2018-01-28 10:05:00,105714,2479.6436
2018-01-28 10:10:00,105714,2781.9711
2018-01-28 10:15:00,105714,2988.8336
2018-01-28 10:20:00,105714,248.1884
2018-01-28 10:25:00,105714,234.4482
2018-01-28 10:30:00,105714,143.856
2018-01-28 10:35:00,105714,243.2
2018-01-28 10:40:00,105714,141.2992
2018-01-28 10:45:00,105714,143.1584
2018-01-28 10:50:00,105714,239.7988
2018-01-28 10:55:00,105714,2650.8354
2018-01-28 11:00:00,105714,2694.4128
2018-01-28 11:05:00,105714,2550.4995
2018-01-28 11:10:00,105714,2561.844
2018-01-28 11:15:00,105714,2610.3827
2018-01-28 11:20:00,105714,2679.4119
2018-01-28 11:25:00,105714,2658.5614
2018-01-28 11:30:00,105714,2914.6217
2018-01-28 11:35:00,105714,2999.2815
2018-01-28 11:40:00,105714,149.2578
2018-01-28 11:45:00,105714,142.9841
2018-01-28 11:50:00,105714,250.614
2018-01-28 11:55:00,105714,324.72
2018-01-28 12:00:00,105714,237.153
2018-01-28 12:05:00,105714,237.2496
2018-01-28 12:10:00,105714,138.953
2018-01-28 12:15:00,105714,2651.06
2018-01-28 12:20:00,105714,2623.8762
2018-01-28 12:25:00,105714,2703.3641
2018-01-28 12:30:00,105714,2692.885
2018-01-28 12:35:00,105714,2687.36
2018-01-28 12:40:00,105714,2566.26
2018-01-28 12:45:00,105714,2620.85
2018-01-28 12:50:00,105714,2722.3727
2018-01-28 12:55:00,105714,3160.6148
2018-01-28 13:00:00,105714,246.3978
2018-01-28 13:05:00,105714,238.6811
2018-01-28 13:10:00,105714,242.055
2018-01-28 13:15:00,105714,141.8221
2018-01-28 13:20:00,105714,141.764
2018-01-28 13:25:00,105714,141.764
2018-01-28 13:30:00,105714,242.78
2018-01-28 13:35:00,105714,2802.144
2018-01-28 13:40:00,105714,2703.7296
2018-01-28 13:45:00,105714,2657.1762
2018-01-28 13:50:00,105714,2602.5443
2018-01-28 13:55:00,105714,2764.124
2018-01-28 14:00:00,105714,321.156
2018-01-28 14:05:00,105714,319.836
2018-01-28 14:10:00,105714,234.8346
2018-01-28 14:15:00,105714,141.1249
2018-01-28 14:20:00,105714,143.7968
2018-01-28 14:25:00,105714,249.878
2018-01-28 14:30:00,105714,2660.0563
2018-01-28 14:35:00,105714,2663.936
2018-01-28 14:40:00,105714,2695.623
2018-01-28 14:45:00,105714,2674.5223
2018-01-28 14:50:00,105714,2774.8398
2018-01-28 14:55:00,105714,2802.5028
2018-01-28 15:00:00,105714,2619.67
2018-01-28 15:05:00,105714,2823.411
2018-01-28 15:10:00,105714,298.9935
2018-01-28 15:15:00,105714,382.36
2018-01-28 15:20:00,105714,375.41
2018-01-28 15:25:00,105714,292.5768
2018-01-28 15:30:00,105714,292.3354
2018-01-28 15:35:00,105714,294.272
2018-01-28 15:40:00,105714,2794.4226
2018-01-28 15:45:00,105714,2835.2545
2018-01-28 15:50:00,105714,2702.4984
2018-01-28 15:55:00,105714,2725.0009
2018-01-28 16:00:00,105714,2711.088
2018-01-28 16:05:00,105714,2658.2652
2018-01-28 16:10:00,105714,2884.64
2018-01-28 16:15:00,105714,2773.9818
2018-01-28 16:20:00,105714,242.2825
2018-01-28 16:25:00,105714,242.78
2018-01-28 16:30:00,105714,240.584
2018-01-28 16:35:00,105714,323.988
2018-01-28 16:40:00,105714,240.2882
2018-01-28 16:45:00,105714,239.6966
2018-01-28 16:50:00,105714,2658.432
2018-01-28 16:55:00,105714,2643.1158
2018-01-28 17:00:00,105714,2809.0832
2018-01-28 17:05:00,105714,2523.0699
2018-01-28 17:10:00,105714,2668.0212
2018-01-28 17:15:00,105714,140.0256
2018-01-28 17:20:00,105714,236.682
2018-01-28 17:25:00,105714,2787.8424
2018-01-28 17:30:00,105714,2676.7299
2018-01-28 17:35:00,105714,2742.8438
2018-01-28 17:40:00,105714,141.0087
2018-01-28 17:45:00,105714,140.7182
2018-01-28 17:50:00,105714,324.146
2018-01-28 17:55:00,105714,2740.0212
2018-01-28 18:00:00,105714,2658.3432
2018-01-28 18:05:00,105714,2663.4852
2018-01-28 18:10:00,105714,2499.5212
2018-01-28 18:15:00,105714,2940.6942
2018-01-28 18:20:00,105714,239.679
2018-01-28 18:25:00,105714,238.9078
2018-01-28 18:30:00,105714,234.3516
2018-01-28 18:35:00,105714,317.2089
2018-01-28 18:40:00,105714,321.6213
2018-01-28 18:45:00,105714,408.944
2018-01-28 18:50:00,105714,2715.3042
2018-01-28 18:55:00,105714,2783.6046
2018-01-28 19:00:00,105714,2854.5996
2018-01-28 19:05:00,105714,2887.024
2018-01-28 19:10:00,105714,2880.914
2018-01-28 19:15:00,105714,2779.114
2018-01-28 19:20:00,105714,2701.6152
2018-01-28 19:25:00,105714,2819.6645
2018-01-28 19:30:00,105714,3058.5749
2018-01-28 19:35:00,105714,500.992
2018-01-28 19:40:00,105714,420.3199
2018-01-28 19:45:00,105714,415.53
2018-01-28 19:50:00,105714,417.0294
2018-01-28 19:55:00,105714,509.25
2018-01-28 20:00:00,105714,502.596
2018-01-28 20:05:00,105714,422.5078
2018-01-28 20:10:00,105714,2764.8144
2018-01-28 20:15:00,105714,2717.8081
2018-01-28 20:20:00,105714,2809.08
2018-01-28 20:25:00,105714,2833.7569
2018-01-28 20:30:00,105714,2746.3228
2018-01-28 20:35:00,105714,2739.1
2018-01-28 20:40:00,105714,2667.5248
2018-01-28 20:45:00,105714,2800.8362
2018-01-28 20:50:00,105714,3081.3952
2018-01-28 20:55:00,105714,423.054
2018-01-28 21:00:00,105714,332.4321
2018-01-28 21:05:00,105714,328.9232
2018-01-28 21:10:00,105714,499.177
2018-01-28 21:15:00,105714,510.669
2018-01-28 21:20:00,105714,385.6689
2018-01-28 21:25:00,105714,381.582
2018-01-28 21:30:00,105714,2701.0962
2018-01-28 21:35:00,105714,2818.34
2018-01-28 21:40:00,105714,2701.482
2018-01-28 21:45:00,105714,2574.804
2018-01-28 21:50:00,105714,2582.272
2018-01-28 21:55:00,105714,2656.6064
2018-01-28 22:00:00,105714,2626.4616
2018-01-28 22:05:00,105714,2788.6928
2018-01-28 22:10:00,105714,2932.2939
2018-01-28 22:15:00,105714,391.876
2018-01-28 22:20:00,105714,296.9744
2018-01-28 22:25:00,105714,299.2892
2018-01-28 22:30:00,105714,495.311
2018-01-28 22:35:00,105714,388.1601
2018-01-28 22:40:00,105714,386.5356
2018-01-28 22:45:00,105714,386.5356
2018-01-28 22:50:00,105714,2722.8672
2018-01-28 22:55:00,105714,2733.8542
2018-01-28 23:00:00,105714,2625.0912
2018-01-28 23:05:00,105714,2562.1766
2018-01-28 23:10:00,105714,2592.2008
2018-01-28 23:15:00,105714,2589.37
2018-01-28 23:20:00,105714,2657.328
2018-01-28 23:25:00,105714,2570.3145
2018-01-28 23:30:00,105714,2753.9908
2018-01-28 23:35:00,105714,221.0149
2018-01-28 23:40:00,105714,218.283
2018-01-28 23:45:00,105714,404.432
2018-01-28 23:50:00,105714,313.8699
2018-01-28 23:55:00,105714,306.3879
2018-01-28 00:00:00,105715,85.8168
2018-01-28 00:05:00,105715,32.214
2018-01-28 00:10:00,105715,11.3988
2018-01-28 00:15:00,105715,11.8752
2018-01-28 00:20:00,105715,190.575
2018-01-28 00:25:00,105715,188.1
2018-01-28 00:30:00,105715,178.8702
2018-01-28 00:35:00,105715,168.436
2018-01-28 00:40:00,105715,175.867
2018-01-28 00:45:00,105715,31.6928
2018-01-28 00:50:00,105715,11.3666
2018-01-28 00:55:00,105715,12.1226
2018-01-28 01:00:00,105715,187.796
2018-01-28 01:05:00,105715,175.015
2018-01-28 01:10:00,105715,153.14
2018-01-28 01:15:00,105715,153.078
2018-01-28 01:20:00,105715,163.152
2018-01-28 01:25:00,105715,165.624
2018-01-28 01:30:00,105715,12.1226
2018-01-28 01:35:00,105715,12.103
2018-01-28 01:40:00,105715,26.9775
2018-01-28 01:45:00,105715,190.96
2018-01-28 01:50:00,105715,156.681
2018-01-28 01:55:00,105715,153.884
2018-01-28 02:00:00,105715,163.614
2018-01-28 02:05:00,105715,166.696
2018-01-28 02:10:00,105715,149.22
2018-01-28 02:15:00,105715,12.2059
2018-01-28 02:20:00,105715,27.1192
2018-01-28 02:25:00,105715,32.5928
2018-01-28 02:30:00,105715,189.6618
2018-01-28 02:35:00,105715,187.248
2018-01-28 02:40:00,105715,202.1068
2018-01-28 02:45:00,105715,209.7422
2018-01-28 02:50:00,105715,10.1926
2018-01-28 02:55:00,105715,10.2295
2018-01-28 03:00:00,105715,179.064
2018-01-28 03:05:00,105715,206.67
2018-01-28 03:10:00,105715,169.32
2018-01-28 03:15:00,105715,164.34
2018-01-28 03:20:00,105715,171.81
2018-01-28 03:25:00,105715,174.09
2018-01-28 03:30:00,105715,154.318
2018-01-28 03:35:00,105715,154.504
2018-01-28 03:40:00,105715,164.34
2018-01-28 03:45:00,105715,32.6714
2018-01-28 03:50:00,105715,12.48
2018-01-28 03:55:00,105715,12.2255
2018-01-28 04:00:00,105715,174.44
2018-01-28 04:05:00,105715,171.81
2018-01-28 04:10:00,105715,154.318
2018-01-28 04:15:00,105715,152.012
2018-01-28 04:20:00,105715,161.98
2018-01-28 04:25:00,105715,166.629
2018-01-28 04:30:00,105715,12.9584
2018-01-28 04:35:00,105715,12.9324
2018-01-28 04:40:00,105715,27.639
2018-01-28 04:45:00,105715,181.77
2018-01-28 04:50:00,105715,156.87
2018-01-28 04:55:00,105715,154.38
2018-01-28 05:00:00,105715,164.01
2018-01-28 05:05:00,105715,166.026
2018-01-28 05:10:00,105715,12.1618
2018-01-28 05:15:00,105715,12.1373
2018-01-28 05:20:00,105715,27.5946
2018-01-28 05:25:00,105715,235.98
2018-01-28 05:30:00,105715,161.2
2018-01-28 05:35:00,105715,153.884
2018-01-28 05:40:00,105715,163.548
2018-01-28 05:45:00,105715,166.495
2018-01-28 05:50:00,105715,147.609
2018-01-28 05:55:00,105715,12.1716
2018-01-28 06:00:00,105715,27.6057
2018-01-28 06:05:00,105715,32.6583
2018-01-28 06:10:00,105715,166.763
2018-01-28 06:15:00,105715,156.933
2018-01-28 06:20:00,105715,164.472
2018-01-28 06:25:00,105715,167.165
2018-01-28 06:30:00,105715,149.52
2018-01-28 06:35:00,105715,12.48
2018-01-28 06:40:00,105715,27.9552
2018-01-28 06:45:00,105715,32.6845
2018-01-28 06:50:00,105715,164.604
2018-01-28 06:55:00,105715,156.051
2018-01-28 07:00:00,105715,163.548
2018-01-28 07:05:00,105715,168.3
2018-01-28 07:10:00,105715,149.0672
2018-01-28 07:15:00,105715,146.8962
2018-01-28 07:20:00,105715,26.9448
2018-01-28 07:25:00,105715,31.6544
2018-01-28 07:30:00,105715,11.3252
2018-01-28 07:35:00,105715,167.28
2018-01-28 07:40:00,105715,166.6
2018-01-28 07:45:00,105715,169.048
2018-01-28 07:50:00,105715,149.792
2018-01-28 07:55:00,105715,169.1108
2018-01-28 08:00:00,105715,178.92
2018-01-28 08:05:00,105715,74.0232
2018-01-28 08:10:00,105715,168.21
2018-01-28 08:15:00,105715,286.9817
2018-01-28 08:20:00,105715,399.763
2018-01-28 08:25:00,105715,275.724
2018-01-28 08:30:00,105715,180.127
2018-01-28 08:35:00,105715,173.666
2018-01-28 08:40:00,105715,577.492
2018-01-28 08:45:00,105715,583.814
2018-01-28 08:50:00,105715,220.8738
2018-01-28 08:55:00,105715,58.6835
2018-01-28 09:00:00,105715,41.225
2018-01-28 09:05:00,105715,54.7904
2018-01-28 09:10:00,105715,342.4047
2018-01-28 09:15:00,105715,227.478
2018-01-28 09:20:00,105715,187.572
2018-01-28 09:25:00,105715,199.588
2018-01-28 09:30:00,105715,179.968
2018-01-28 09:35:00,105715,182.1
2018-01-28 09:40:00,105715,181.95
2018-01-28 09:45:00,105715,184.756
2018-01-28 09:50:00,105715,11.6496
2018-01-28 09:55:00,105715,10.4146
2018-01-28 10:00:00,105715,10.4146
2018-01-28 10:05:00,105715,210.801
2018-01-28 10:10:00,105715,176.514
2018-01-28 10:15:00,105715,174.6
2018-01-28 10:20:00,105715,171.891
2018-01-28 10:25:00,105715,183.616
2018-01-28 10:30:00,105715,166.773
2018-01-28 10:35:00,105715,10.4146
2018-01-28 10:40:00,105715,10.872
2018-01-28 10:45:00,105715,30.87
2018-01-28 10:50:00,105715,183.6
2018-01-28 10:55:00,105715,174.802
2018-01-28 11:00:00,105715,172.34
2018-01-28 11:05:00,105715,184.125
2018-01-28 11:10:00,105715,167.144
2018-01-28 11:15:00,105715,11.7744
2018-01-28 11:20:00,105715,11.2838
2018-01-28 11:25:00,105715,1793.4
2018-01-28 11:30:00,105715,229.736
2018-01-28 11:35:00,105715,200.572
2018-01-28 11:40:00,105715,193.076
2018-01-28 11:45:00,105715,195.12
2018-01-28 11:50:00,105715,185.516
2018-01-28 11:55:00,105715,180.19
2018-01-28 12:00:00,105715,10.962
2018-01-28 12:05:00,105715,15.3405
2018-01-28 12:10:00,105715,8.54
2018-01-28 12:15:00,105715,407.647
2018-01-28 12:20:00,105715,404.376
2018-01-28 12:25:00,105715,405.142
2018-01-28 12:30:00,105715,408.744
2018-01-28 12:35:00,105715,28.188
2018-01-28 12:40:00,105715,35.1335
2018-01-28 12:45:00,105715,2312.931
2018-01-28 12:50:00,105715,250.702
2018-01-28 12:55:00,105715,1775.58
2018-01-28 13:00:00,105715,2400.9286
2018-01-28 13:05:00,105715,2549.5392
2018-01-28 13:10:00,105715,2548.513
2018-01-28 13:15:00,105715,2576.4769
2018-01-28 13:20:00,105715,2559.3228
2018-01-28 13:25:00,105715,2555.8496
2018-01-28 13:30:00,105715,244.824
2018-01-28 13:35:00,105715,242.5
2018-01-28 13:40:00,105715,213.4
2018-01-28 13:45:00,105715,203.448
2018-01-28 13:50:00,105715,201.358
2018-01-28 13:55:00,105715,198.44
2018-01-28 14:00:00,105715,195.291
2018-01-28 14:05:00,105715,194.643
2018-01-28 14:10:00,105715,219.583
2018-01-28 14:15:00,105715,2383.3371
2018-01-28 14:20:00,105715,2576.8656
2018-01-28 14:25:00,105715,2545.862
2018-01-28 14:30:00,105715,2426.567
2018-01-28 14:35:00,105715,191.022
2018-01-28 14:40:00,105715,184.954
2018-01-28 14:45:00,105715,183.388
2018-01-28 14:50:00,105715,182.248
2018-01-28 14:55:00,105715,10.3028
2018-01-28 15:00:00,105715,10.0968
2018-01-28 15:05:00,105715,212.621
2018-01-28 15:10:00,105715,224.942
2018-01-28 15:15:00,105715,224.378
2018-01-28 15:20:00,105715,193.185
2018-01-28 15:25:00,105715,188.573
2018-01-28 15:30:00,105715,182.248
2018-01-28 15:35:00,105715,1955.8125
2018-01-28 15:40:00,105715,2431.6882
2018-01-28 15:45:00,105715,2521.6605
2018-01-28 15:50:00,105715,2493.0738
2018-01-28 15:55:00,105715,11.2471
2018-01-28 16:00:00,105715,10.2641
2018-01-28 16:05:00,105715,10.737
2018-01-28 16:10:00,105715,232.024
2018-01-28 16:15:00,105715,229.248
2018-01-28 16:20:00,105715,217.399
2018-01-28 16:25:00,105715,232.315
2018-01-28 16:30:00,105715,230.016
2018-01-28 16:35:00,105715,227.905
2018-01-28 16:40:00,105715,201.516
2018-01-28 16:45:00,105715,196.226
2018-01-28 16:50:00,105715,191.2
2018-01-28 16:55:00,105715,189.047
2018-01-28 17:00:00,105715,189.442
2018-01-28 17:05:00,105715,184.492
2018-01-28 17:10:00,105715,188.968
2018-01-28 17:15:00,105715,188.573
2018-01-28 17:20:00,105715,213.066
2018-01-28 17:25:00,105715,214.29
2018-01-28 17:30:00,105715,220.317
2018-01-28 17:35:00,105715,223.25
2018-01-28 17:40:00,105715,195.98
2018-01-28 17:45:00,105715,188.257
2018-01-28 17:50:00,105715,188.415
2018-01-28 17:55:00,105715,187.862
2018-01-28 18:00:00,105715,2156.88
2018-01-28 18:05:00,105715,199.5
2018-01-28 18:10:00,105715,213.66
2018-01-28 18:15:00,105715,213.3
2018-01-28 18:20:00,105715,214.11
2018-01-28 18:25:00,105715,195.652
2018-01-28 18:30:00,105715,183.337
2018-01-28 18:35:00,105715,180.88
2018-01-28 18:40:00,105715,178.5
2018-01-28 18:45:00,105715,179.1
2018-01-28 18:50:00,105715,10.7145
2018-01-28 18:55:00,105715,10.4984
2018-01-28 19:00:00,105715,10.728
2018-01-28 19:05:00,105715,224.566
2018-01-28 19:10:00,105715,220.968
2018-01-28 19:15:00,105715,220.038
2018-01-28 19:20:00,105715,191.889
2018-01-28 19:25:00,105715,194.668
2018-01-28 19:30:00,105715,189.76
2018-01-28 19:35:00,105715,188.415
2018-01-28 19:40:00,105715,183.491
2018-01-28 19:45:00,105715,60.843
2018-01-28 19:50:00,105715,60.69
2018-01-28 19:55:00,105715,59.9004
2018-01-28 20:00:00,105715,221.4849
2018-01-28 20:05:00,105715,221.578
2018-01-28 20:10:00,105715,248.0093
2018-01-28 20:15:00,105715,246.3426
2018-01-28 20:20:00,105715,203.867
2018-01-28 20:25:00,105715,43.7346
2018-01-28 20:30:00,105715,43.9166
2018-01-28 20:35:00,105715,212.7615
2018-01-28 20:40:00,105715,238.194
2018-01-28 20:45:00,105715,236.18
2018-01-28 20:50:00,105715,236.964
2018-01-28 20:55:00,105715,230.85
2018-01-28 21:00:00,105715,224.13
2018-01-28 21:05:00,105715,244.521
2018-01-28 21:10:00,105715,261.4417
2018-01-28 21:15:00,105715,272.16
2018-01-28 21:20:00,105715,1814.648
2018-01-28 21:25:00,105715,237.454
2018-01-28 21:30:00,105715,235.031
2018-01-28 21:35:00,105715,233.184
2018-01-28 21:40:00,105715,228.514
2018-01-28 21:45:00,105715,318.854
2018-01-28 21:50:00,105715,316.81
2018-01-28 21:55:00,105715,336.444
2018-01-28 22:00:00,105715,293.4
2018-01-28 22:05:00,105715,265.14
2018-01-28 22:10:00,105715,267.813
2018-01-28 22:15:00,105715,213.933
2018-01-28 22:20:00,105715,186.884
2018-01-28 22:25:00,105715,183.675
2018-01-28 22:30:00,105715,186.352
2018-01-28 22:35:00,105715,11.2838
2018-01-28 22:40:00,105715,11.3206
2018-01-28 22:45:00,105715,34.2079
2018-01-28 22:50:00,105715,229.896
2018-01-28 22:55:00,105715,222.21
2018-01-28 23:00:00,105715,189.882
2018-01-28 23:05:00,105715,185.55
2018-01-28 23:10:00,105715,187.264
2018-01-28 23:15:00,105715,180.675
2018-01-28 23:20:00,105715,180.821
2018-01-28 23:25:00,105715,200.7264
2018-01-28 23:30:00,105715,18.2928
2018-01-28 23:35:00,105715,36.803
2018-01-28 23:40:00,105715,12.1471
2018-01-28 23:45:00,105715,183.594
2018-01-28 23:50:00,105715,208.824
2018-01-28 23:55:00,105715,201.358
- I am trying to create a line plot for each household according to their unique id. The date will on the
x-axis
, power_usage on they-axis
and a line for each value of House_id. - As there are
3214 households
with 903814 readings in total. I am trying tocreate a subplots
with a line plot. For example, the first plot will show the power usage readings of first 20 households (20 subplots in total), the next plot will cover the power usage readings of next 20 households (20 subplots in total) and so on. The total plots will be 160 with 3214 subplots.Is there a way to automatically iterate this and get all the plots
? As an example, I have attached a demo picture in below image.
The output should be like this:
Solution
- This implementation uses
seaborn.relplot
- Create a list of unique
'House_id'
values - Create groups of 20
'House_id'
values from the unique list - Iterate through the list of groups:
- Filter
df
to only include data for'House_id'
values in the group - Save or plot the data
- Filter
- The
'Date'
column in the following test set is already adatetime
dtype.- Use
df.Date = pd.to_datetime(df.Date)
to convert the'Date'
column of the real data. Substitute your column name for'Date'
.
- Use
- After converting the
'Date'
column to the correct dtype, optionally sortdf
withdf = df.sort_values(['House_id', 'Date'])
Imports and Test Data
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
import numpy as np
# create test data
hid = range(40)
date_range = pd.bdate_range('2018-01-28', '2019-01-28', freq='2W').tolist()
Date = list()
House_id = list()
power_Usage = list()
for v in hid:
len_dr = len(date_range)
l = [v] * len_dr
Date += date_range
House_id += l
np.random.seed(v)
power_Usage += np.random.randint(100, 400, size=(len_dr)).tolist()
df = pd.DataFrame({'Date': Date, 'House_id': House_id, 'power_Usage': power_Usage})
# display(df.head())
Date House_id power_Usage
0 2018-01-28 0 272
1 2018-02-11 0 147
2 2018-02-25 0 217
3 2018-03-11 0 292
4 2018-03-25 0 351
Plot the DataFrame
# get the unique ids
unique_ids = df.House_id.unique()
# create groups of 20 ids
N = 20
groups = [unique_ids[n:n+N] for n in range(0, len(unique_ids), N)]
# iterate through the groups of ids and plot
for i, group in enumerate(groups):
data = df[df.House_id.isin(group)]
g = sns.relplot(data=data, x='Date', y='power_Usage', col='House_id', col_wrap=4, kind='line', facet_kws={'sharey': False}, height=3)
g.set_xticklabels(rotation=90)
g.savefig(f'group_{i}.png')
plt.show()
Group 1
Group 2
Update using OP sample data
- Sample data was added after the answer was posted.
- Using Formatting Date labels using Seaborn FacetGrid to format the xaxis labels.
- The default format for a 24-hour period is
'%m-%d %H'
(e.g.'01-28 03'
).
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
import matplotlib.dates as mdates
# load the file
df = pd.read_csv('data_sample.csv')
# set the datetime
df.datetime = pd.to_datetime(df.datetime)
# create formatting for the xaxis labels
xformatter = mdates.DateFormatter('%Y-%m-%d %H')
# get the unique ids
unique_ids = df.House_id.unique()
# create groups of 20 ids
N = 2
groups = [unique_ids[n:n+N] for n in range(0, len(unique_ids), N)]
# iterate through the groups of ids and plot
for i, group in enumerate(groups):
data = df[df.House_id.isin(group)]
g = sns.relplot(data=data, x='datetime', y='power_Usage', col='House_id', col_wrap=4, kind='line', facet_kws={'sharey': False}, height=3)
g.set_xticklabels(rotation=90)
# set the format to the axis
g.axes[0].xaxis.set_major_formatter(xformatter)
g.savefig(f'group_{i}.png')
plt.show()
Answered By - Trenton McKinney
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.