import numpy as np, pandas as pd, matplotlib.pyplot as plt import yfinance as yf df = yf.download("AAPL", period="3mo", progress=False) close = df["Close"].squeeze() # handle yfinance multiindex print("AAPL last:", round(float(close.iloc[-1]),2), "| 20d SMA:", round(float(close.rolling(20).mean().iloc[-1]),2)) close.plot(title="AAPL 3mo"); plt.savefig("aapl.png")