less than 1 minute read

지역구 에너지 소비량 데이터

import pandas as pd
df= pd.read_csv('https://raw.githubusercontent.com/Datamanim/datarepo/main/consum/Tetuan%20City%20power%20consumption.csv')
df.head()
DateTime Temperature Humidity Wind Speed general diffuse flows diffuse flows Zone 1 Power Consumption Zone 2 Power Consumption Zone 3 Power Consumption
0 1/1/2017 0:00 6.559 73.8 0.083 0.051 0.119 34055.69620 16128.87538 20240.96386
1 1/1/2017 0:10 6.414 74.5 0.083 0.070 0.085 29814.68354 19375.07599 20131.08434
2 1/1/2017 0:20 6.313 74.5 0.080 0.062 0.100 29128.10127 19006.68693 19668.43373
3 1/1/2017 0:30 6.121 75.0 0.083 0.091 0.096 28228.86076 18361.09422 18899.27711
4 1/1/2017 0:40 5.921 75.7 0.081 0.048 0.085 27335.69620 17872.34043 18442.40964

Q53. 3월달의 각 시간대별 온도의 평균들 중 가장 높은 시간대의 온도를 출력하라

index를 2개 가진 dataframe indexing 하는 법 (loc 이용)

df_2 = df.groupby([df.DateTime.dt.month, df.DateTime.dt.hour]).Temperature.mean().to_frame()
df_2
Temperature
DateTime DateTime
1 0 11.511484
1 11.278425
2 11.111419
3 11.082419
4 10.848376
... ... ...
12 19 14.031889
20 13.558500
21 13.145556
22 12.935611
23 12.610639

288 rows × 1 columns

# loc 을 이용하여 index부분에 (x,y) 와 같이 2차원으로 넣어 준다.

df_2.loc[(3,)].sort_values('Temperature', ascending = False).head()
Temperature
DateTime
15 18.393602
14 18.377581
16 18.164731
13 18.111989
17 17.783817

Leave a comment