In [1]:
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
%matplotlib inline
import warnings
warnings.filterwarnings('ignore')
In [2]:
consumption_df = pd.read_csv('consumption_monthly.csv', header=0, skiprows=4, na_values='.')
In [3]:
consumption_df['CONSUMPTION'] = consumption_df['CONSUMPTION'].str.replace(',', '')
consumption_df['CONSUMPTION'] = consumption_df['CONSUMPTION'].apply(int)
In [4]:
consumption_df.info()
In [5]:
consumption_df.head()
Out[5]:
In [8]:
states_df = consumption_df.groupby("STATE")["CONSUMPTION"].sum().sort_values(ascending=False).head(21).to_frame()
states_df = states_df.drop('US-Total')
states_df
Out[8]:
In [9]:
ax = states_df.plot(kind='bar', title ="Per State Consumption",figsize=(15,10),legend=True, fontsize=12)
ax.set_xlabel("State",fontsize=12)
ax.set_ylabel("Consumption",fontsize=12)
Out[9]:
In [10]:
producer_df = consumption_df.groupby("TYPE OF PRODUCER")["CONSUMPTION"].sum().sort_values(ascending=False)
producer_df
Out[10]:
In [11]:
ax = producer_df.plot(kind='bar', title ="Consumption by Producer Type",figsize=(15,10),legend=True, fontsize=12)
ax.set_xlabel("Type of Producer",fontsize=12)
ax.set_ylabel("Consumption",fontsize=12)
Out[11]:
In [12]:
energy_df = consumption_df.groupby("ENERGY SOURCE")["CONSUMPTION"].sum().sort_values(ascending=False)
energy_df
Out[12]:
In [13]:
ax = energy_df.plot(kind='bar', title ="Consumption by Energy Source",figsize=(15,10),legend=True, fontsize=12)
ax.set_xlabel("Energy Source",fontsize=12)
ax.set_ylabel("Consumption",fontsize=12)
Out[13]: