In [ ]:
import seaborn as sns
import matplotlib.pyplot as plt
import pandas as pd
import numpy as np
In [ ]:
df=pd.read_csv('energy.csv')
df.head()
Out[ ]:
Date commercial industrial
0 1/1/01 629 13128
1 2/1/01 548 11421
2 3/1/01 553 12454
3 4/1/01 550 11674
4 5/1/01 575 11751
In [ ]:
df.dtypes
Out[ ]:
0
Date object
commercial int64
industrial int64

In [ ]:
df['Date']=pd.to_datetime(df['Date'])
df.head()
/tmp/ipython-input-3951332809.py:1: UserWarning: Could not infer format, so each element will be parsed individually, falling back to `dateutil`. To ensure parsing is consistent and as-expected, please specify a format.
  df['Date']=pd.to_datetime(df['Date'])
Out[ ]:
Date commercial industrial
0 2001-01-01 629 13128
1 2001-02-01 548 11421
2 2001-03-01 553 12454
3 2001-04-01 550 11674
4 2001-05-01 575 11751
In [ ]:
#1. Load the energy dataset into colab and create a line
# chart showing the commercial energy generation over time
plt.figure(figsize=(12,5))
plt.plot_date(x=df['Date'], y=df['commercial'], linestyle='--', linewidth=2,
              c='blue', marker= 'x', markersize=10, mfc='black', mec='red',
              fmt='x--')
plt.title('Commercial Energy Over Time')
plt.xlabel('Date')
plt.show()
/tmp/ipython-input-2017423839.py:4: MatplotlibDeprecationWarning: The plot_date function was deprecated in Matplotlib 3.9 and will be removed in 3.11. Use plot instead.
  plt.plot_date(x=df['Date'], y=df['commercial'], linestyle='--', linewidth=2,
/tmp/ipython-input-2017423839.py:4: UserWarning: linestyle is redundantly defined by the 'linestyle' keyword argument and the fmt string "x--" (-> linestyle='--'). The keyword argument will take precedence.
  plt.plot_date(x=df['Date'], y=df['commercial'], linestyle='--', linewidth=2,
/tmp/ipython-input-2017423839.py:4: UserWarning: marker is redundantly defined by the 'marker' keyword argument and the fmt string "x--" (-> marker='x'). The keyword argument will take precedence.
  plt.plot_date(x=df['Date'], y=df['commercial'], linestyle='--', linewidth=2,
No description has been provided for this image
In [ ]:
#2. Create one figure that display both commercial
# and industrial energy generations over time together
plt.figure(figsize=(12,5))
sns.lineplot(data= df, x='Date',y='commercial', linestyle='--', markersize='8',
             marker='o', color='peru', mfc='lime', mec='yellow', label='commercial')
sns.lineplot(data=df, x='Date',y='industrial', linestyle='--', markersize='12',
             marker='.', color='teal', mfc='magenta', mec='crimson', label='industrial')
plt.show()
No description has been provided for this image
In [ ]:
#3. Create a function func_(x) using python,
# which is the x cubed plus two times x squared plus twelve
def func_(x):
  outcome= x**3 + 2 * x**2 + 12
  return outcome
In [ ]:
#4. Define input x along with its the output of
# function y and visualize their relation
x = np.linspace(1,10,100)
y = func_(x)
In [ ]:
plt.figure(figsize=(4, 4))
plt.plot(x, y, color='indigo', linestyle='--', linewidth=3)
#plt.title('Cubic Function')
plt.xlabel('x')
plt.ylabel('y')
plt.grid()
plt.show()
No description has been provided for this image
In [ ]:
#5. transform your ipynb file to the html file
!jupyter nbconvert --to html bana310_HW2and3.ipynb
[NbConvertApp] Converting notebook bana310_HW2and3.ipynb to html
[NbConvertApp] WARNING | Alternative text is missing on 3 image(s).
[NbConvertApp] Writing 442364 bytes to bana310_HW2and3.html
In [ ]: