Arrays and NumPy
NumPy is a scientific computing package in Python that helps you to work with arrays. Let's use array operations to calculate price to earning ratios of the S&P 100 stocks.
The S&P 100 data is available as the lists: prices (stock prices per share) and earnings (earnings per share).
Diese Übung ist Teil des Kurses
Introduction to Python for Finance
Anleitung zur Übung
- Import the
numpyasnp. - Convert the
pricesandearningslists to arrays,prices_arrayandearnings_array, respectively. - Calculate the price to earnings ratio as
pe.
Interaktive Übung
Vervollständige den Beispielcode, um diese Übung erfolgreich abzuschließen.
# Import numpy as np
import ____ as ____
# Convert lists to arrays
prices_array = ____(prices)
earnings_array = ____(earnings)
# Calculate P/E ratio
pe = ____
print(pe)