import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
%matplotlib inline
month = pd.DataFrame()
for i in range(10):
i = str(i)
path = 'data/GREEND/dataset_2014-04-1' + i + '.csv'
day = pd.read_csv(path, sep=',')
month = month.append(day)
building.index = building['datetime']
building = building.groupby(pd.Grouper(freq='H')).mean()
building.head()
time
Coffee machine
washing machine
radio
water kettle
fridge
dishwasher
kitchen lamp
TV
vacuum cleaner
Power
datetime
2014-04-09 21:00:00
1.397081e+09
1.170731
0.000000
0.550232
0.0
0.0
0.0
0.00000
0.00000
0.0
1.720963
2014-04-09 22:00:00
1.397083e+09
17.312213
0.013444
0.566091
0.0
0.0
0.0
0.00000
0.00000
0.0
17.891748
2014-04-09 23:00:00
1.397086e+09
25.322587
0.003758
0.561381
0.0
0.0
0.0
0.00000
0.00000
0.0
25.887726
2014-04-10 00:00:00
1.397090e+09
14.767736
0.000000
0.562385
0.0
0.0
0.0
0.00074
0.00206
0.0
15.332921
2014-04-10 01:00:00
1.397093e+09
28.574747
0.000000
0.565088
0.0
0.0
0.0
0.00000
0.00000
0.0
29.139835
# building 데이터에 연, 월, 일, 시, 분, 초를 나타내는 새로운 컬럼을 생성합니다.
# 각각의 이름을 datetime-month/day/hour/minute/second라고 지정합니다.
# 이 컬럼에 날짜(datetime) 컬럼의 dt(datetime의 약자입니다) 옵션을 활용하여 월일시분을 따로 넣어줍니다.
building["datetime-month"] = building.index.month
building["datetime-day"] = building.index.day
building["datetime-hour"] = building.index.hour
# dayofweek는 날짜에서 요일(월~일)을 가져오는 기능입니다.
# 값은 0(월), 1(화), 2(수), 3(목), 4(금), 5(토), 6(일) 을 나타냅니다.
building["datetime-dayofweek"] = building.index.dayofweek
# building 변수에 할당된 데이터의 행렬 사이즈를 출력합니다.
# 출력은 (row, column) 으로 표시됩니다.
print(building.shape)
# .head()로 building 데이터의 상위 5개를 띄우되,
# datetime과 이와 연관된 나머지 다섯 개의 컬럼만을 출력합니다.
building[["datetime-month", "datetime-day",
"datetime-hour", "datetime-dayofweek"]].head()
# 세탁기, 냉장고의 전력 소비량이 총 전력 소비량과 가장 연관이 높습니다.
# 전기 물 끓이기(water kettle) 은 연관성이 매우 낮음을 알 수 있습니다.
corr = building[apps].corrwith(building['Power'])
sorted(zip(map(lambda x : str(x)[:6], corr.values), corr.index), reverse=True)