Get the largest consumer company listed after 1998
You can filter your data by even more conditions by enclosing each condition in parentheses and using logical operators like &
and |
.
Here, you will find out which company is the largest consumer services company that went public after Amazon did in 1997. The data is contained in the column 'IPO Year'
; an Initial Public Offering (IPO) is a financial term that describes the first time that the stock of a private company is offered to the public.
DataReader
, date
, pandas
as pd
, and matplotlib.pyplot
as plt
have been imported. The listings
DataFrame from the last exercise is also available.
This exercise is part of the course
Importing and Managing Financial Data in Python
Exercise instructions
- Set
'Stock Symbol'
as the index forlistings
. - Use
.loc[]
to filter rows where'Sector'
is'Consumer Services'
andIPO Year
starting 1998, and also select the'Market Capitalization'
column. Apply.idxmax()
and assign the result toticker
. - Set the
start
date to January 1, 2015. - Use the
DataReader
to get the stock data for theticker
from'yahoo'
sincestart
. - Plot the
'close'
and'volume'
prices of this company, using'volume'
forsecondary_y
andticker
as thetitle
.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Set Stock Symbol as the index
listings = ____
# Get ticker of the largest consumer services company listed after 1997
ticker = listings.loc[(____ == ____) & (____ > 1998), 'Market Capitalization'].____()
# Set the start date
start = ____
# Import the stock data
data = ____
# Plot close and volume
data[['close', 'volume']].____
# Show the plot
plt.show()