ComeçarComece de graça

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.

Este exercício faz parte do curso

Importing and Managing Financial Data in Python

Ver curso

Instruções do exercício

  • 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.

Exercício interativo prático

Experimente este exercício completando este código de exemplo.

# 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()
Editar e executar o código