- Prep the data
- Visualize the consumption over time (can be changed monthly, yearly etc.)
- Look for daily trends through out the day
- Look for trends throughout the week
- Give insight into how much energy needs to be accounted for
View Full Python Code File --> Click Me
- Prepped the data by importing pandas and adding in additional columns:
power_cols = ["Datetime", "PowerConsumption_Zone1", "PowerConsumption_Zone2", "PowerConsumption_Zone3"]
powerconsumption = pd.read_csv(
"powerconsumption.csv",
usecols=power_cols,
parse_dates=["Datetime"]
).assign(total_consumption = lambda x: x["PowerConsumption_Zone1"] + x["PowerConsumption_Zone2"] + x["PowerConsumption_Zone3"],
hour = lambda x: x["Datetime"].dt.hour,
day_of_week = lambda x: x["Datetime"].dt.dayofweek
)
- We also created a day of the week list and column that we use later for analysis:
day_of_week = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday","Sunday"]
powerconsumption["day_name"] = pd.Categorical(powerconsumption["Datetime"].dt.day_name(), categories=day_of_week)
- Created an area line chart to show the electricity consumption throughout a month. The variable can easily be changed to show other months:
import seaborn as sns
(powerconsumption
.set_index(["Datetime"])
.resample("H")
.mean()
.loc["2017-01", ["PowerConsumption_Zone1", "PowerConsumption_Zone2", "PowerConsumption_Zone3"]]
.plot
.area(
title="Hourly Eclectricity Consumption by Zone - Jan 2017",
xlabel="Date",
ylabel="Consumption (KwH)"
)
)
sns.despine()
- Create a heatmap to show weekly/hourly trends:
sns.heatmap(
powerconsumption.pivot_table(
index="day_name",
columns="hour",
values="total_consumption",
aggfunc="mean"
),
cbar=None,
cmap="viridis"
).set(title="Power Consumption by Day of Week and Hour",
ylabel="Day of Week",
xlabel="Hour");
Heatmap:
- Based off of objectives 3 and 4 we are able to gain insight with our visuals. We see that energy consumption is heavy in early day time but drops off.
- Most of the days tend to be a similar story, but starting Friday going into the weekend we start to see larger energy consumptions early in the day.
- We'd also see from our area line chart, we need to keep the committee informed that they need to be able to handle at least 100,000 KwH at any given time.