A closer look at the sectors

Introduzione a Python per la finanza

Adina Howe

Instructor

Your mission

Given

NumPy arrays of data describing the S&P 100: names, prices, earnings, sectors

Objective Part II

Explore and analyze sector-specific P/E ratios within companies of the S&P 100

Introduzione a Python per la finanza

Step 1: Create a boolean filtering array

stock_prices = np.array([100, 200, 300])
filter_array = (stock_prices >= 150)
print(filter_array)
[ False True  True]
Introduzione a Python per la finanza

Step 2: Apply filtering array to subset another array

stock_prices = np.array([100, 200, 300])
filter_array = (stock_prices >= 150)
print(stock_prices[filter_array])
[200 300]
Introduzione a Python per la finanza

Step 3: Summarize P/E ratios

Calculate the average and standard deviation of these sector-specific P/E ratios

import numpy as np
average_value = np.mean(my_array)
std_value = np.std(my_array)
Introduzione a Python per la finanza

Let's practice!

Introduzione a Python per la finanza

Preparing Video For Download...