Get startedGet started for free

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

View Course

Exercise instructions

  • Set 'Stock Symbol' as the index for listings.
  • Use .loc[] to filter rows where 'Sector' is 'Consumer Services' and IPO Year starting 1998, and also select the 'Market Capitalization' column. Apply .idxmax() and assign the result to ticker.
  • Set the start date to January 1, 2015.
  • Use the DataReader to get the stock data for the ticker from 'yahoo' since start.
  • Plot the 'close' and 'volume' prices of this company, using 'volume' for secondary_y and ticker as the title.

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()
Edit and Run Code