本篇通过几行 Python 代码对上市公司的市值进行排序,运行时为获取每日的最新数据。AKShare 库的安装命令为:pip install akshare --upgrade。
这是之前的两篇:
市值排序的 Python 代码如下:
"""
This code is supported by the website: https://www.guanjihuan.com
The newest version of this code is on the web page: https://www.guanjihuan.com/archives/38193
"""
import akshare as ak
import numpy as np
stocks = ak.stock_zh_a_spot_em()
stock_data = stocks.values
new_stock_data = []
for stock in stock_data:
if np.isnan(float(stock[9])):
continue
else:
new_stock_data.append(stock)
new_stock_data = np.array(new_stock_data)
list_index = np.argsort(new_stock_data[:, 17])
list_index = list_index[::-1]
for i0 in range(30):
stock_symbol = new_stock_data[list_index[i0], 1]
stock_name = new_stock_data[list_index[i0], 2]
market_capitalization = new_stock_data[list_index[i0], 17]/1e8
print([i0+1, stock_symbol, stock_name, market_capitalization])
2024年01月28日运行的结果为(市值单位为亿元):点击展开
[1, '600941', '中国移动', 21692.28142661]
[2, '600519', '贵州茅台', 20567.97781896]
[3, '601398', '工商银行', 18141.07848583]
[4, '601939', '建设银行', 17100.75086004]
[5, '601857', '中国石油', 15556.78311453]
[6, '601288', '农业银行', 13509.3451075]
[7, '601988', '中国银行', 12599.79746511]
[8, '600938', '中国海油', 10883.27559954]
[9, '601628', '中国人寿', 8089.358571]
[10, '600036', '招商银行', 7848.41595103]
[11, '601318', '中国平安', 7511.72177539]
[12, '601088', '中国神华', 7112.93014389]
[13, '600028', '中国石化', 6946.1264458]
[14, '300750', '宁德时代', 6598.561854]
[15, '600900', '长江电力', 5904.18093487]
[16, '002594', '比亚迪', 5410.6501103]
[17, '601728', '中国电信', 5261.66047519]
[18, '000858', '五 粮 液', 5084.90648655]
[19, '601658', '邮储银行', 4620.90614337]
[20, '601328', '交通银行', 4433.48478071]
[21, '000333', '美的集团', 4041.23001248]
[22, '688981', '中芯国际', 3695.17392435]
[23, '300760', '迈瑞医疗', 3447.21337142]
[24, '601166', '兴业银行', 3249.09924972]
[25, '601899', '紫金矿业', 3217.10700553]
[26, '600030', '中信证券', 3087.11990448]
[27, '002415', '海康威视', 2957.80049513]
[28, '601998', '中信银行', 2952.70201703]
[29, '601138', '工业富联', 2862.39119709]
[30, '600276', '恒瑞医药', 2570.73791642]
2024年10月22日运行的结果为(市值单位为亿元):点击展开
[1, '600941', '中国移动', 22410.51528089]
[2, '601398', '工商银行', 21883.34418526]
[3, '601939', '建设银行', 20350.89356736]
[4, '600519', '贵州茅台', 19383.132054]
[5, '601288', '农业银行', 17009.17544623]
[6, '601857', '中国石油', 15483.5747234]
[7, '601988', '中国银行', 14542.75688731]
[8, '600938', '中国海油', 13393.94103269]
[9, '601628', '中国人寿', 12351.676085]
[10, '300750', '宁德时代', 11030.15223868]
[11, '601318', '中国平安', 10390.75986675]
[12, '600036', '招商银行', 9878.61352191]
[13, '002594', '比亚迪', 8865.98769311]
[14, '601088', '中国神华', 8233.51466935]
[15, '600028', '中国石化', 8032.18837694]
[16, '688981', '中芯国际', 7658.69283645]
[17, '600900', '长江电力', 6870.67553465]
[18, '601728', '中国电信', 6085.22472348]
[19, '000333', '美的集团', 5851.73569968]
[20, '000858', '五 粮 液', 5645.41068247]
[21, '601658', '邮储银行', 5493.52361251]
[22, '601328', '交通银行', 5473.16295374]
[23, '601138', '工业富联', 5217.31301422]
[24, '601899', '紫金矿业', 4797.30895367]
[25, '600030', '中信证券', 4100.84530758]
[26, '601166', '兴业银行', 3976.2013494]
[27, '601601', '中国太保', 3712.48976748]
[28, '601998', '中信银行', 3621.12477315]
[29, '300059', '东方财富', 3572.26826209]
[30, '002475', '立讯精密', 3327.66912431]
美股市值排序的 Python 代码如下:
"""
This code is supported by the website: https://www.guanjihuan.com
The newest version of this code is on the web page: https://www.guanjihuan.com/archives/38193
"""
import akshare as ak
import numpy as np
stocks = ak.stock_us_spot_em()
stock_data = stocks.values
new_stock_data = []
for stock in stock_data:
if np.isnan(float(stock[9])):
continue
else:
new_stock_data.append(stock)
new_stock_data = np.array(new_stock_data)
list_index = np.argsort(new_stock_data[:, 9])
list_index = list_index[::-1]
for i0 in range(30):
stock_symbol = new_stock_data[list_index[i0], 15]
stock_name = new_stock_data[list_index[i0], 1]
market_capitalization = new_stock_data[list_index[i0], 9]/1e8
print([i0+1, stock_symbol, stock_name, market_capitalization])
2024年01月28日运行的结果为(市值单位为亿美元):点击展开
[1, '105.MSFT', '微软', 30021.13722553]
[2, '105.AAPL', '苹果', 29751.7802832]
[3, '107.FBGX', 'FI Enhanced Large Cap Growth ET', 24137.94058165]
[4, '105.GOOG', '谷歌-C', 19248.3564]
[5, '105.GOOGL', '谷歌-A', 19048.1004]
[6, '105.AMZN', '亚马逊', 16443.50946844]
[7, '105.NVDA', '英伟达', 15050.2446]
[8, '105.META', 'Meta Platforms Inc-A', 10128.8569719]
[9, '106.TSM', '台积电', 6081.58929092]
[10, '106.LLY', '礼来', 6068.44651252]
[11, '105.TSLA', '特斯拉', 5825.37344901]
[12, '105.AVGO', '博通', 5640.53208777]
[13, '106.BRK_B', '伯克希尔哈撒韦-B', 5042.62791442]
[14, '106.JPM', '摩根大通', 4980.62916987]
[15, '106.V', '维萨', 4920.74409554]
[16, '106.NVO', '诺和诺德', 4816.43441467]
[17, '106.UNH', '联合健康', 4654.22407438]
[18, '106.WMT', '沃尔玛', 4422.53230392]
[19, '106.XOM', '埃克森美孚', 4116.67770822]
[20, '106.MA', '万事达', 4112.4293603]
[21, '106.JNJ', '强生', 3839.6093989]
[22, '106.PG', '宝洁', 3674.00707372]
[23, '106.HD', '家得宝', 3536.16533173]
[24, '105.ASML', '阿斯麦', 3413.7285]
[25, '106.BRK_A', '伯克希尔哈撒韦-A', 3329.160498]
[26, '106.ORCL', '甲骨文', 3151.3641808]
[27, '106.MRK', '默沙东', 3061.60669009]
[28, '105.COST', '开市客', 3047.88174382]
[29, '107.NRGU', 'MicroSectors U.S. Big Oil Index', 3044.18311415]
[30, '106.ABBV', '艾伯维', 2902.54352012]
2024年10月22日运行的结果为(市值单位为亿美元):点击展开
[1, '105.AAPL', '苹果', 35797.22831828]
[2, '105.NVDA', '英伟达', 35129.24129]
[3, '105.MSFT', '微软', 31919.69671953]
[4, '105.GOOG', '谷歌-C', 20501.074]
[5, '105.GOOGL', '谷歌-A', 20294.266]
[6, '105.AMZN', '亚马逊', 19981.46022805]
[7, '105.META', 'Meta Platforms Inc-A', 14709.11354697]
[8, '106.TSM', '台积电', 10301.62492]
[9, '106.LLY', '礼来', 8651.53482155]
[10, '105.AVGO', '博通', 8398.62991245]
[11, '105.TSLA', '特斯拉', 6945.78719029]
[12, '106.WMT', '沃尔玛', 6600.60995153]
[13, '106.JPM', '摩根大通', 6308.80577]
[14, '106.BRK_B', '伯克希尔哈撒韦-B', 6113.37807791]
[15, '106.XOM', '埃克森美孚', 5367.3787913]
[16, '106.UNH', '联合健康', 5272.34826924]
[17, '106.V', '维萨', 5201.22642169]
[18, '106.NVO', '诺和诺德', 5175.48536414]
[19, '106.ORCL', '甲骨文', 4849.77610197]
[20, '106.MA', '万事达', 4744.49315612]
[21, '106.PG', '宝洁', 4009.6940478]
[22, '106.HD', '家得宝', 3989.21519604]
[23, '105.COST', '开市客', 3950.5322706]
[24, '106.JNJ', '强生', 3936.32484428]
[25, '106.BRK_A', '伯克希尔哈撒韦-A', 3829.19944941]
[26, '107.FNGU', 'MicroSectors FANG Index 3X Leve', 3387.90630751]
[27, '106.ABBV', '艾伯维', 3326.55517496]
[28, '105.NFLX', '奈飞', 3271.29420063]
[29, '106.BAC', '美国银行', 3245.81334028]
[30, '106.KO', '可口可乐', 2995.78935107]
354 次浏览
【说明:本站主要是个人的一些笔记和代码分享,内容可能会不定期修改。为了使全网显示的始终是最新版本,这里的文章未经同意请勿转载。引用请注明出处:https://www.guanjihuan.com】