すべての取引所におけるテクノロジー企業のIPO件数(年別)
listings 辞書の各企業には、1972年から2017年の間のIPO年が入っています。したがって、この文脈では、dtype が float64 であっても、各シートの 'IPO Year' 列を明確な順序を持つカテゴリ変数として扱うのが適切です。
ここでは、3つの取引所すべてのデータを結合し、Technology セクターの企業におけるIPO年の分布を可視化します。pandas は pd、matplotlib.pyplot は plt としてインポート済みで、前の演習の listings 辞書もワークスペースに用意されています。
この演習はコースの一部です
Pythonでの金融データのインポートと管理
演習の手順
- 各取引所名を含む反復変数
exchangeを使って for ループを作成します。- 各反復で、
listingsのキーexchangeに対応する DataFrame をall_listingsに追加します。
- 各反復で、
- ループ終了後、
pd.concat()を使ってall_listingsの3つの DataFrame を結合し、結果をlisting_dataに代入します。 listing_dataを'Technology'企業にフィルタリングし、結果をtech_companiesに代入します。tech_companiesの'IPO Year'列をipo yearsに代入します。- このデータに対して、
.dropna()で欠損値を削除し、.astype()でintに変換します。 ipo_yearsに.value_counts()を適用し、年を昇順に並べ替えて、タイトルを'Tech IPOs by Year'とする棒グラフを作成します。xticksを45度回転させ、結果を表示します。
実践的なインタラクティブ演習
このサンプルコードを完成させて、この演習に挑戦してみましょう。
# Create lists
exchanges = ['amex', 'nasdaq', 'nyse']
all_listings = []
# Use for loop to create listing_data
for exchange in exchanges:
all_listings.____(____[____])
# Combine DataFrames
listing_data = pd.____(____)
# Select tech companies
tech_companies = listing_data[____.____ == 'Technology']
# Create ipo_years
ipo_years = ____[____]
# Drop missing values and convert to int
ipo_years = ipo_years.____().____(int)
# Count values, sort ascending by year, and create a bar plot
ipo_years.____().plot(kind=____, ____='Tech IPOs by Year')
# Rotate xticks and show result
plt.xticks(____=____)
# Show the plot
plt.show()