Giter VIP home page Giter VIP logo

Comments (3)

Micro-sheep avatar Micro-sheep commented on July 25, 2024 2

如果把 efinance 更新到 0.4.4 及其之后的版本,则可以按下面这样子做

import efinance as ef
df = ef.stock.get_belong_board('600519')
df

运行结果

image

from efinance.

Micro-sheep avatar Micro-sheep commented on July 25, 2024 1

没有直接提供获取股票所属板块和概念的函数,不过提供了获取板块成员股信息的函数,你根据成员股信息进行统计即可。例如下面的例子

import pandas as pd
import efinance as ef
from efinance.common import get_realtime_quotes_by_fs


def get_stock_info_df() -> pd.DataFrame:
    concept = '概念板块'
    industry = '行业板块'
    bk = {
        concept: ef.stock.get_realtime_quotes(concept).set_index('股票代码', drop=False),
        industry: ef.stock.get_realtime_quotes(
            industry).set_index('股票代码', drop=False)
    }

    rows = []
    for bk_type, bk_df in bk.items():
        for bk_id, row in bk_df.iterrows():
            df = get_realtime_quotes_by_fs(f'b:{bk_id}').rename(columns={
                '代码': '股票代码',
                '名称': '股票名称',
            })
            for row2 in df.iloc:
                rows.append({
                    '股票代码': row2['股票代码'],
                    '股票名称': row2['股票名称'],
                    '板块类型': bk_type,
                    '板块名称': row['股票名称'],
                    '板块代码': bk_id,
                })
    stock_info_df = pd.DataFrame(rows)
    stock_info_df.index = stock_info_df['股票代码'].values
    return stock_info_df


# 这个函数调用一次就行 会汇总全部股票板块分布信息
df = get_stock_info_df()
# 查看某一只股票情况
df.loc['600519']

运行结果

image

from efinance.

xiaoxiaodetian avatar xiaoxiaodetian commented on July 25, 2024

感谢

from efinance.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.