深入觀察產業

Python 金融入門

Adina Howe

Professor

你的任務

已知

描述 S&P 100 的 NumPy 陣列:names、prices、earnings、sectors

目標(二)

在 S&P 100 公司中探索並分析各產業的本益比(P/E)

Python 金融入門

步驟 1:建立布林過濾陣列

stock_prices = np.array([100, 200, 300])
filter_array = (stock_prices >= 150)
print(filter_array)
[ False True  True]
Python 金融入門

步驟 2:套用過濾陣列來篩出另一個陣列

stock_prices = np.array([100, 200, 300])
filter_array = (stock_prices >= 150)
print(stock_prices[filter_array])
[200 300]
Python 金融入門

步驟 3:彙整 P/E

計算這些產業本益比的平均與標準差

import numpy as np
average_value = np.mean(my_array)
std_value = np.std(my_array)
Python 金融入門

一起來練習吧!

Python 金融入門

Preparing Video For Download...