In [1]:
import seaborn as sns
import matplotlib.pyplot as plt
import pandas as pd
In [2]:
df=pd.read_csv('annual_gold.csv')
df.head()
Out[2]:
| Date | Gold | Platinum | |
|---|---|---|---|
| 0 | 1986-12 | 391.595 | 465.29 |
| 1 | 1987-12 | 487.079 | 556.63 |
| 2 | 1988-12 | 419.248 | 530.29 |
| 3 | 1989-12 | 409.655 | 509.68 |
| 4 | 1990-12 | 378.161 | 471.29 |
In [6]:
df.dtypes
Out[6]:
| 0 | |
|---|---|
| Date | object |
| Gold | float64 |
| Platinum | float64 |
In [7]:
df['Date']=pd.to_datetime(df['Date'])
df.head()
Out[7]:
| Date | Gold | Platinum | |
|---|---|---|---|
| 0 | 1986-12-01 | 391.595 | 465.29 |
| 1 | 1987-12-01 | 487.079 | 556.63 |
| 2 | 1988-12-01 | 419.248 | 530.29 |
| 3 | 1989-12-01 | 409.655 | 509.68 |
| 4 | 1990-12-01 | 378.161 | 471.29 |
In [8]:
#create the time series line for gold
plt.figure(figsize=(12,5))
plt.plot_date(x=df['Date'], y=df['Gold'], linestyle='--', linewidth=2,
c='blue', marker= 'x', markersize=10, mfc='black', mec='red',
fmt='x--')
plt.title('Gold Price Over Time')
plt.xlabel('Date')
plt.show()
/tmp/ipykernel_2021/174242078.py:3: 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['Gold'], linestyle='--', linewidth=2, /tmp/ipykernel_2021/174242078.py:3: 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['Gold'], linestyle='--', linewidth=2, /tmp/ipykernel_2021/174242078.py:3: 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['Gold'], linestyle='--', linewidth=2,
In [9]:
#compare the price change overtime
plt.figure(figsize=(12,5))
sns.lineplot(data= df, x='Date',y='Gold', linestyle='--', markersize='8',
marker='o', color='gold', mfc='orange', mec='yellow', label='gold')
sns.lineplot(data=df, x='Date',y='Platinum', linestyle='--', markersize='12',
marker='x', color='teal', mfc='black', mec='steelblue', label='platinum')
plt.show()
In [9]:
In [ ]:
!jupyter nbconvert --to html bana310_100725.ipynb
[NbConvertApp] Converting notebook bana310_final.ipynb to html [NbConvertApp] WARNING | Alternative text is missing on 14 image(s). [NbConvertApp] Writing 963726 bytes to bana310_final.html