看到社区有用户提出无法获取到全部的创业板股票,所以现在提供一种方法获取到全部300开通的股票。
代码示例如下:
```
df = get_all_securities(['stock'])
stocks_300 = [code for code in df.index if code.upper().startswith('300')]
log.info(stocks_300)
```
stocks_300 即获取到的300开头股票的列表!
如果要剔除300的股票,则使用下面代码。
```
stocks_no_300 = [code for code in df.index if code not in stocks_300 ]
```
希望帮到大家!
@莫邪的救赎 您好,按照您剔除‘300’开头的方法和思路,我自己在实际编写过程过遇到了困难,请您指教。取中证全指成分股作为初始股票池,剔除创业板股票(‘300’开头的股票):
scu1 = get_index_stocks('000985.XSHG')
#取出300开头的创业板股票
scu_300=[code for code in scu1.index if code.upper().startswith('300')]
#剔除创业板
# scu = [code for code in scu1.index if code not in scu_300]。
报错:Traceback (most recent call last):
File