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.
Deze oefening maakt deel uit van de cursus
Importing and Managing Financial Data in Python
Oefeninstructies
- Set
'Stock Symbol'as the index forlistings. - Use
.loc[]to filter rows where'Sector'is'Consumer Services'andIPO Yearstarting 1998, and also select the'Market Capitalization'column. Apply.idxmax()and assign the result toticker. - Set the
startdate to January 1, 2015. - Use the
DataReaderto get the stock data for thetickerfrom'yahoo'sincestart. - Plot the
'close'and'volume'prices of this company, using'volume'forsecondary_yandtickeras thetitle.
Praktische interactieve oefening
Probeer deze oefening eens door deze voorbeeldcode in te vullen.
# 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()