How to Calculate PE ratio for ETFs via Python in Colab - QCLN
Previously on the How to Calculate PE ratio for ETFs via Python in Colab — QQQ, we discussed how to calculate PE ratio for Invesco QQQ. In this article, we are discussing how to calculate the PE for QCLN.
Step 0
We first need to know the definition of PE ratio.
Install all required packages.
!pip install pandas
!pip install yahoo_fin
!pip install requests
Step 1: Get the shares held by holdings. Unlike the previous articles we were downloading Excel or csv and parse the file to locate the information. We are using pandas to parse the html to locate the table hold the shares/ market value information.
import pandas as pd
import requests
res = requests.get('https://www.ftportfolios.com/Retail/Etf/EtfHoldings.aspx?Ticker=QCLN')
res.encoding = 'big5'
html_df = pd.read_html(res.text)
df_QCLN = html_df[10]
Keep reading with a 7-day free trial
Subscribe to Informula to keep reading this post and get 7 days of free access to the full post archives.