EIA Monthly: Electric Power SectorΒΆ

Monthly generation data from EIA Table 7.2b: https://www.eia.gov/totalenergy/data/monthly/

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt

url = 'https://www.eia.gov/totalenergy/data/browser/csv.php?tbl=T07.02B'
df = pd.read_csv(url)
df = df.loc[~df['Description'].str.contains('Generation Total')]
df = df.loc[~df['YYYYMM'].astype(str).str.endswith('13')]
df['source'] = df['Description'].str.split(",").str[0].str.replace('Electricity Net Generation From ', '')
df['date'] = pd.to_datetime(df['YYYYMM'], format='%Y%m')
df2 = df.pivot(index='date', columns='source', values='Value')
df2 = df2.replace('Not Available', np.nan).astype(float)
df2 = df2.loc[:, df2.max() > 5000]  # only keep the main players
fig, ax = plt.subplots(figsize=(10, 6))
df2.rolling(12, center=True).mean().plot(ax=ax, colormap='tab10')
ax.legend()
ax.set_ylabel('Million kWh')
fig.tight_layout()
df2.plot(ax=ax, alpha=0.2, colormap='tab10', legend=False)
eia monthly

Out:

<AxesSubplot:xlabel='date', ylabel='Million kWh'>
fig, ax = plt.subplots()
df2['Solar'].dropna().plot(ax=ax)
ax.set_ylabel('Million kWh')
fig.suptitle('Solar Monthly Generation')

df2['Solar'].loc['2017-02'].plot(ax=ax, marker='x', color='k', ls='')
Solar Monthly Generation

Out:

<AxesSubplot:xlabel='date', ylabel='Million kWh'>

Total running time of the script: ( 0 minutes 2.121 seconds)

Gallery generated by Sphinx-Gallery