視覺化資料分布

在 Python 中匯入與管理財務資料

Stefan Jansen

Instructor

務必檢視你的資料!

  • 相同指標,可能代表截然不同的資料

務必檢視資料

在 Python 中匯入與管理財務資料

認識 seaborn 圖表

  • 多種美觀又有洞見的統計圖表
  • 建立於 matplotlib 之上
  • 瑞士刀:seaborn.distplot()
    • 長條圖
    • 核密度估計(KDE)
    • 地毯圖
在 Python 中匯入與管理財務資料

10 年期公債:趨勢與分布

ty10 = web.DataReader('DGS10', 'fred', date(1962, 1, 1))
ty10.info()
DatetimeIndex: 15754 entries, 1962-01-02 to 2022-05-20
Data columns (total 1 columns):
 #   Column  Non-Null Count  Dtype  
 --  ------  --------------  -----  
 0   DGS10   15083 non-null  float64
ty10.describe()
              DGS10
mean       6.291073
std        2.851161
min        1.370000
25%        4.190000
50%        6.040000
...
在 Python 中匯入與管理財務資料

10 年期公債:時間序列趨勢

ty10.dropna(inplace=True) # Avoid creation of copy

ty10.plot(title='10-year Treasury'); plt.tight_layout()

10 年期公債走勢

在 Python 中匯入與管理財務資料

10 年期公債:歷史分布

import seaborn as sns
sns.distplot(ty10)

10 年期公債分布直方圖

在 Python 中匯入與管理財務資料

10 年期公債:趨勢與分布

ax = sns.distplot(ty10)
ax.axvline(ty10['DGS10'].median(), color='black', ls='--')

10 年期公債密度與中位數

在 Python 中匯入與管理財務資料

一起來練習吧!

在 Python 中匯入與管理財務資料

Preparing Video For Download...