get_constituents - 查询指数最新成份股
函数原型:
get_constituents(index, fields=None, df=False)参数:
| 参数名 | 类型 | 说明 |
|---|---|---|
| index | str | 指数代码 |
| fields | str or None | 若要有返回权重字段, 可以设置为 ‘symbol, weight’ |
| df | bool | 是否返回dataframe 格式, 默认False, 返回list[dict] |
返回值:
-
参数 fields 为 None时, 返回
list[str], 成分股列表 -
参数 fields 指定为
'symbol, weight', 返回list[dict], dict包含key值:参数名 类型 说明 symbol str 股票symbol weight float 权重
当df = True时,返回
| 类型 | 说明 |
|---|---|
| dataframe | dataframe |
示例1:
get_constituents(index='SHSE.000001', fields='symbol, weight', df=True)输出:
symbol weightSHSE.603966 0.01SHSE.603960 0.01···
当df = False时,返回
| 类型 | 说明 |
|---|---|
| list[dict()] | 列表镶嵌字典 |
示例2:
get_constituents(index='SHSE.000001', fields='symbol, weight', df=False)输出:
[{'symbol': 'SHSE.603681', 'weight': 0.009999999776482582}, {'symbol': 'SHSE.601518', 'weight': 0.009999999776482582}, {'symbol': 'SHSE.600010', 'weight': 0.12999999523162842}···]
只输出 symbol 列表
示例3:
get_constituents(index='SHSE.000001')
输出:
['SHSE.603966', 'SHSE.603960', 'SHSE.603218',···]
注意:
1.在该函数中,index参数只支持输入一个指数代码,若代码输入错误或以'index1,inedx2'方式输入多个代码,函数返回空list/空DataFrame
浙公网安备 33010602011771号