開始使用免費開始

使用 countplot() 繪製所有交易所的 IPO 時間軸

若要快速視覺化資料集中各類別的觀測數量,通常會使用 seaborncountplot() 函式:

seaborn.countplot(x=None, hue=None, data=None, ...)

參數 x 放的是 data 引數(也就是要繪製的 DataFrame)中變數的名稱。hue 則以顏色標示另一個類別變數。以上是此函式眾多參數中的三個可選參數;完整清單請見 seaborn文件

現在用這個工具來比較三大交易所的 IPO 活動時間軸。pandas 作為 pdmatplotlib.pyplot 作為 plt、以及 seaborn 作為 sns 都已匯入,且含有參考欄位 'Exchange'listings DataFrame 已在你的工作區中可用。

本練習屬於課程

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

檢視課程

練習說明

  • listings 篩選為只包含 2000 年之後的 IPO 年份。
  • 將欄位 'IPO Year' 的資料轉成整數。
  • 繪製 listingssns.countplot()x 變數使用 'IPO Year'hue 使用 'Exchange'
  • xticks() 旋轉 45 度並顯示結果。

動手互動練習

試著完成這個範例程式碼,體驗一下這個練習。

# Select IPOs after 2000
listings = listings[____[____] > ____]

# Convert IPO Year to integer
listings['IPO Year'] = ____[____].____(____)

# Create a countplot
sns.countplot(x=____, hue=____, data=____)

# Rotate xticks and show result
plt.xticks(rotation=45)

# Show the plot
plt.show()
編輯並執行程式碼