Median market capitalization by IPO year
In the last lesson of the previous chapter, you created a timeline for the number of IPOs per year for technology companies.
Let's now analyze how market capitalization has evolved for different IPO years. You can combine data from all three exchanges to get a more comprehensive view.
pandas
as pd
and matplotlib.pyplot
as plt
have been imported, and the listings
DataFrame from previous exercises which now includes an added reference column 'exchange'
that contains the exchange for each listed company, is available in your workspace.
This exercise is part of the course
Importing and Managing Financial Data in Python
Exercise instructions
- Inspect and display
listings
using.info()
and.head()
. - Using broadcasting, create a new column
market_cap_m
forlistings
that contains the market cap in millions of USD. - Select all companies with an
'IPO Year'
after 1985. - Drop all missing values in the
'IPO Year
' column, and convert the remaining values todtype
integer. - Group
listings
by'IPO Year'
, select themarket_cap_m
column and calculate themedian
, sort with.sort_index()
, and assign the result toipo_by_year
. - Plot and show the results as a bar chart.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Inspect listings
listings.____()
# Show listings head
print(listings.____())
# Create market_cap_m
listings['market_cap_m'] = ____[____].div(1e6)
# Select companies with IPO after 1985
listings = listings[____[____] > ____]
# Drop missing values and convert to integers
listings['IPO Year'] = ____[____].dropna().____(int)
# Calculate the median market cap by IPO Year and sort the index
ipo_by_year = listings.____(____).____.median().____()
# Plot results as a bar chart
ipo_by_year.plot(kind='bar')
# Show the plot
plt.show()