데이터 : 전력거래소 신재생에너지 데이터(에너지원별, 시간별) 기간 : 2019-2021년

In [1]:
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
In [2]:
plt.rcParams['figure.figsize'] = (14, 9)
plt.rcParams['font.family'] = 'Malgun Gothic'
plt.rcParams['font.size'] = 12
plt.rcParams['axes.unicode_minus']
Out[2]:
True
In [3]:
# 데이터 읽고, 시간, 일 데이터 정리하는 함수
def data_setting():
    df = pd.read_excel('신재생발전량및설비용량_2019_2021.xlsx')
    df = df.set_index('거래일자')

    pv = df[df['연료원구분'] == '태양광'].copy()
    wt = df[df['연료원구분'] == '풍력'].copy()

    pv_hour = pv.drop('연료원구분', axis=1)
    wt_hour = wt.drop('연료원구분', axis=1)

    pv_hour['이용률'] = pv_hour['전력거래량(MWh)'] / pv_hour['설비용량(MW)'] * 100
    wt_hour['이용률'] = wt_hour['전력거래량(MWh)'] / wt_hour['설비용량(MW)'] * 100

    pv = pv.reset_index()
    wt = wt.reset_index()
    pv_day = pv.groupby('거래일자').agg({'설비용량(MW)': 'mean', '전력거래량(MWh)': 'sum'})
    pv_day['이용률'] = pv_day['전력거래량(MWh)'] / (pv_day['설비용량(MW)'] * 24) * 100
    # print(pv_day.head())
    wt_day = wt.groupby('거래일자').agg({'설비용량(MW)': 'mean', '전력거래량(MWh)': 'sum'})
    wt_day['이용률'] = wt_day['전력거래량(MWh)'] / (wt_day['설비용량(MW)'] * 24) * 100

    return pv_hour, pv_day, wt_hour, wt_day
In [4]:
# 월로 계절을 구분하는 함수
def to_season(month_num):
    season = 'winter'

    if 3<= month_num <=5:
        season = 'spring'
    elif 6<= month_num <=8:
        season = 'summer'
    elif 9<= month_num <=11:
        season = 'autumn'

    return season
In [5]:
pv_hour, pv_day, wt_hour, wt_day = data_setting() # 데이터 읽기
print(pv_hour.info())
<class 'pandas.core.frame.DataFrame'>
DatetimeIndex: 26304 entries, 2019-01-01 to 2021-12-31
Data columns (total 4 columns):
 #   Column      Non-Null Count  Dtype  
---  ------      --------------  -----  
 0   거래시간        26304 non-null  int64  
 1   설비용량(MW)    26304 non-null  float64
 2   전력거래량(MWh)  26304 non-null  float64
 3   이용률         26304 non-null  float64
dtypes: float64(3), int64(1)
memory usage: 1.0 MB
None
In [6]:
# 전체/4계절 이용률 (시간 기준)
def hour_ur(df, type): # 1 태양광, 2 풍력
    df['월'] = df.index.month
    df['계절'] = df['월'].apply(to_season)
    #print(df)

    spring = df[df['계절'] == 'spring']
    summer = df[df['계절'] == 'summer']
    autumn = df[df['계절'] == 'autumn']
    winter = df[df['계절'] == 'winter']

    graph = df['이용률'].groupby(df['거래시간']).mean()
    graph = pd.DataFrame(graph)
    graph.columns = ['전체']
    graph['봄'] = spring['이용률'].groupby(spring['거래시간']).mean()
    graph['여름'] = summer['이용률'].groupby(summer['거래시간']).mean()
    graph['가을'] = autumn['이용률'].groupby(autumn['거래시간']).mean()
    graph['겨울'] = winter['이용률'].groupby(winter['거래시간']).mean()

    print(graph)

    graph.plot()

    if type == 1:
        plt.title('2021년 태양광 전체/4계절 시간대별 이용률')
    if type == 2:
        plt.title('2021년 풍력 전체/4계절 시간대별 이용률')
    plt.ylabel('이용률(%)')
    plt.legend(loc='best')
    plt.grid(which='both')
    plt.show()
In [7]:
hour_ur(pv_hour, 1) # 태양광
             전체          봄         여름         가을         겨울
거래시간                                                       
1      0.217366   0.249635   0.199867   0.199034   0.220791
2      0.096560   0.086331   0.091409   0.086846   0.122010
3      0.060578   0.051131   0.058039   0.055675   0.077723
4      0.032349   0.029028   0.032778   0.028741   0.038928
5      0.020147   0.013935   0.016937   0.021286   0.028596
6      0.075331   0.087607   0.167138   0.018619   0.026459
7      1.368222   2.135149   3.057442   0.221510   0.021934
8      6.722577  10.672702  11.040666   4.682825   0.356619
9     17.908625  25.278438  21.920498  17.261748   6.968595
10    31.348418  39.932587  32.173260  31.604826  21.507508
11    31.144401  38.167957  29.723543  29.969174  26.622232
12    35.593135  42.860408  32.956580  33.553848  32.931316
13    37.503813  44.996608  34.756610  34.508717  35.687864
14    38.134270  46.522884  35.754589  34.221589  35.956028
15    36.972564  46.912353  35.709516  32.156673  32.987170
16    30.163969  40.019630  31.976363  24.508112  23.978235
17    20.785123  29.104941  27.401651  14.124008  12.283472
18    16.379764  20.498426  22.977147  12.138205   9.738870
19    14.111366  14.846688  17.639876  12.898971  10.990210
20    13.266781  14.066720  14.283504  13.783532  10.896038
21    10.037731  11.595305  10.114335  10.421399   7.986904
22     5.654900   7.151055   5.553474   5.687614   4.201481
23     2.063767   2.662890   1.906797   2.063112   1.614118
24     0.592213   0.772830   0.510752   0.565466   0.518173
In [8]:
hour_ur(wt_hour, 2) # 풍력
             전체          봄         여름         가을         겨울
거래시간                                                       
1     22.006812  23.218418  14.535692  19.234181  31.174910
2     22.114442  22.982020  14.574060  19.647253  31.395756
3     22.121049  22.863631  14.512445  19.769765  31.482385
4     22.095219  22.719500  14.247749  19.941843  31.620945
5     22.074301  22.664563  14.045468  20.258373  31.479446
6     22.023790  22.802045  13.720771  20.414569  31.308485
7     21.538456  22.351481  13.204548  20.208667  30.537704
8     20.805788  21.228386  12.587447  19.796550  29.762049
9     19.829090  20.065417  12.069709  18.855784  28.471433
10    20.819641  22.672925  12.018312  18.506919  30.225669
11    20.480367  22.762672  12.095004  17.895971  29.299495
12    19.778852  21.673847  12.146503  17.556823  27.860490
13    19.534629  20.741059  12.270198  17.764649  27.487446
14    20.684919  20.336268  15.685279  19.236887  27.590603
15    21.182410  20.995784  15.828374  19.769672  28.248463
16    21.401961  22.040100  14.443218  19.747470  29.505883
17    21.528654  23.185205  13.248381  19.642641  30.174518
18    21.530570  23.322774  12.656735  19.829608  30.456374
19    22.435597  23.236521  12.271496  22.776983  31.627621
20    22.922136  23.876414  12.896353  23.122073  31.959602
21    22.805587  24.148840  13.510442  21.797965  31.919253
22    22.366087  24.065727  13.706729  20.541484  31.292281
23    22.038191  23.762576  14.053347  19.546448  30.924290
24    22.001302  23.437342  14.494278  19.389746  30.815128
In [9]:
# 산점/라인 이용률 그래프(시간 기준)
def scatter_ur(df, type): # 1 태양광, 2 풍력
    df.plot(x='거래시간', y='이용률', style='.')
    df.groupby('거래시간')['이용률'].mean().plot(legend=True, label='평균 이용률(%)')
    plt.ylabel('이용률(%)')

    if type == 1:
        plt.title('2021년 태양광 이용률(%)')
    if type == 2:
        plt.title('2021년 풍력 이용률(%)')

    plt.grid()
    plt.show()
In [10]:
scatter_ur(pv_hour, 1) # 태양광
In [12]:
scatter_ur(wt_hour, 2) # 풍력
In [13]:
def month_box(df, type):
    #print(df)
    df['month'] = df.index.month
    df.boxplot(column='이용률', by='month')  # 월별로 부하율을 4분위 그래프 그리기
    plt.show()
In [14]:
month_box(pv_day, 1) # 태양광
In [15]:
month_box(wt_day, 2) # 풍력
In [16]:
def ess(type): # 1 태양광, 2 풍력
    data = pd.read_excel('신재생연계ESS설비용량_2018_2021.xlsx')
    data.columns = ['연도', '월', '지역', '태양광', '풍력', 'ESS태양광', 'ESS풍력', '태양광ESS', '풍력ESS']
    data = data[data['연도'] == 2021]

    grp_ess = data.groupby('월')['태양광', '풍력', 'ESS태양광', 'ESS풍력'].sum()

    grp_ess['태양광연계비율'] = grp_ess['ESS태양광'] / grp_ess['태양광'] * 100
    grp_ess['풍력연계비율'] = grp_ess['ESS풍력'] / grp_ess['풍력'] * 100
    grp_ess = grp_ess.reset_index()
    #grp_ess = grp_ess.set_index('월')
    print(grp_ess)

    fig, ax1 = plt.subplots()
    ax2 = ax1.twinx()

    if type == 1:
        grp_ess['태양광'].plot(kind='bar', ax=ax1, sharex=True)
        #ax1 = sns.barplot(data=grp_ess, x='월', y='태양광')
        ax1.set_ylabel('설비용량(MW)')
        grp_ess['태양광연계비율'].plot(kind='line', ax=ax2, color='r', marker='o')
        #ax2 = sns.lineplot(data=grp_ess, x='월', y='태양광연계비율')
        ax2.set_ylabel('연계비율(%)')
        plt.title('2021년 태양광 설비용량(MW) 및 ESS 연계비율(%)')
        plt.xticks(np.arange(12), labels=[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12])

    if type == 2:
        grp_ess['풍력'].plot(kind='bar', ax=ax1, sharex=True)
        ax1.set_ylabel('설비용량(MW)')
        #grp_ess['태양광연계비율'].plot(kind='line', ax=ax2, color='r', marker='o')
        grp_ess['풍력연계비율'].plot(kind='line', ax=ax2, color='r', marker='o')
        ax2.set_ylabel('연계비율(%)')
        plt.title('2021년 풍력 설비용량(MW) 및 ESS 연계비율(%)')
        plt.ylim(10, 30) # 우측 y축 범위 설정
        plt.xticks(np.arange(12), labels=[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12])

    plt.grid()
    plt.show()
In [17]:
ess(1) # 태양광
     월          태양광        풍력       ESS태양광  ESS풍력    태양광연계비율     풍력연계비율
0    1  4697.100000  1692.200  1863.000000  503.6  39.662771  29.760076
1    2  4738.000000  1692.200  1863.000000  503.6  39.320388  29.760076
2    3  4844.900000  1692.200  1863.000000  503.6  38.452806  29.760076
3    4  4898.400000  1692.200  1863.000000  503.6  38.032827  29.760076
4    5  4980.800000  1692.200  1862.500000  503.6  37.393591  29.760076
5    6  5051.500000  1692.200  1862.500000  503.6  36.870237  29.760076
6    7  5130.600000  1692.200  1862.500000  503.6  36.301797  29.760076
7    8  5193.500000  1692.200  1862.500000  503.6  35.862135  29.760076
8    9  5588.304310  1820.573  2022.657286  501.5  36.194473  27.546273
9   10  5743.707400  1820.573  2022.657286  501.5  35.215187  27.546273
10  11  5579.378095  1707.933  1981.042376  501.5  35.506509  29.362979
11  12  5825.742501  1726.733  1981.042376  501.5  34.004977  29.043286
<ipython-input-16-a431036f3fff>:6: FutureWarning: Indexing with multiple keys (implicitly converted to a tuple of keys) will be deprecated, use a list instead.
  grp_ess = data.groupby('월')['태양광', '풍력', 'ESS태양광', 'ESS풍력'].sum()
In [18]:
ess(2) # 풍력
     월          태양광        풍력       ESS태양광  ESS풍력    태양광연계비율     풍력연계비율
0    1  4697.100000  1692.200  1863.000000  503.6  39.662771  29.760076
1    2  4738.000000  1692.200  1863.000000  503.6  39.320388  29.760076
2    3  4844.900000  1692.200  1863.000000  503.6  38.452806  29.760076
3    4  4898.400000  1692.200  1863.000000  503.6  38.032827  29.760076
4    5  4980.800000  1692.200  1862.500000  503.6  37.393591  29.760076
5    6  5051.500000  1692.200  1862.500000  503.6  36.870237  29.760076
6    7  5130.600000  1692.200  1862.500000  503.6  36.301797  29.760076
7    8  5193.500000  1692.200  1862.500000  503.6  35.862135  29.760076
8    9  5588.304310  1820.573  2022.657286  501.5  36.194473  27.546273
9   10  5743.707400  1820.573  2022.657286  501.5  35.215187  27.546273
10  11  5579.378095  1707.933  1981.042376  501.5  35.506509  29.362979
11  12  5825.742501  1726.733  1981.042376  501.5  34.004977  29.043286
<ipython-input-16-a431036f3fff>:6: FutureWarning: Indexing with multiple keys (implicitly converted to a tuple of keys) will be deprecated, use a list instead.
  grp_ess = data.groupby('월')['태양광', '풍력', 'ESS태양광', 'ESS풍력'].sum()