In this notebook we will download list of NIKKEI 225 stocks with pandas. To leverage power of pandas we will need to find the list of the NIKKEI 225 companies that is stored in html table on some website.
We chose to use unofficial source topforeignstocks.com because it contains components in html table. Hence downloading the data is much easier. Official source would be https://indexes.nikkei.co.jp/en/nkave/index/component?idx=nk225.
import pandas as pd
# There is only one table on the page
payload=pd.read_html('https://topforeignstocks.com/indices/the-components-of-the-nikkei-225-index/')
table_0 = payload[0]
df = table_0
df.head()
Company tickers have numerical values (only cash has alphabetical ticker):
symbols = df['Ticker'].values.tolist()
print(symbols[:15])
Show related company names:
names = df['Company Name'].values.tolist()
print(names[:15])
df
Use below code to print the whole dataframe (or just save it to database or csv file):
#with pd.option_context('display.max_rows', None, 'display.max_columns', None):
# print(df)