本文整理汇总了Python中tushare.stock.fundamental.get_stock_basics函数的典型用法代码示例。如果您正苦于以下问题:Python get_stock_basics函数的具体用法?Python get_stock_basics怎么用?Python get_stock_basics使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_stock_basics函数的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_area_classified
def get_area_classified():
"""
获取地域分类数据
Return
--------
DataFrame
code :股票代码
name :股票名称
area :地域名称
"""
df = fd.get_stock_basics()
df = df[['name', 'area']]
df.reset_index(level=0, inplace=True)
df = df.sort('area').reset_index(drop=True)
return df
示例2: get_gem_classified
def get_gem_classified():
"""
获取创业板股票
Return
--------
DataFrame
code :股票代码
name :股票名称
"""
df = fd.get_stock_basics()
df.reset_index(level=0, inplace=True)
df = df[ct.FOR_CLASSIFY_B_COLS]
df = df.ix[df.code.str[0] == '3']
df = df.sort('code').reset_index(drop=True)
return df
示例3: get_sme_classified
def get_sme_classified(file_path=None):
"""
获取中小板股票
Return
--------
DataFrame
code :股票代码
name :股票名称
"""
df = fd.get_stock_basics(file_path)
df.reset_index(level=0, inplace=True)
df = df[ct.FOR_CLASSIFY_B_COLS]
df = df.ix[df.code.str[0:3] == '002']
df = df.sort('code').reset_index(drop=True)
return df
示例4: get_st_classified
def get_st_classified():
"""
获取风险警示板股票
Return
--------
DataFrame
code :股票代码
name :股票名称
"""
df = fd.get_stock_basics()
df.reset_index(level=0, inplace=True)
df = df[ct.FOR_CLASSIFY_B_COLS]
df = df.ix[df.name.str.contains('ST')]
df = df.sort('code').reset_index(drop=True)
return df
示例5: get_sme_classified
def get_sme_classified():
"""
获取中小板股票
Return
--------
DataFrame
code :股票代码
name :股票名称
"""
df = fd.get_stock_basics()
df.reset_index(level=0, inplace=True)
df = df[ct.FOR_CLASSIFY_B_COLS]
df = df.ix[df.code.str[0:3] == "002"]
df = df.sort("code").reset_index(drop=True)
return df
示例6: get_hs300s
def get_hs300s():
"""
获取沪深300当前成份股及所占权重
Return
--------
DataFrame
code :股票代码
name :股票名称
date :日期
weight:权重
"""
from tushare.stock.fundamental import get_stock_basics
try:
wt = pd.read_excel(ct.HS300_CLASSIFY_URL_FTP%(ct.P_TYPE['ftp'], ct.DOMAINS['idxip'],
ct.PAGES['hs300w']), parse_cols=[0, 3, 6])
wt.columns = ct.FOR_CLASSIFY_W_COLS
wt['code'] = wt['code'].map(lambda x :str(x).zfill(6))
df = get_stock_basics()[['name']]
df = df.reset_index()
return pd.merge(df,wt)
except Exception as er:
print(str(er))
示例7: get_zz500s
def get_zz500s():
"""
获取中证500成份股
Return
--------
DataFrame
code :股票代码
name :股票名称
"""
from tushare.stock.fundamental import get_stock_basics
try:
# df = pd.read_excel(ct.HS300_CLASSIFY_URL_FTP%(ct.P_TYPE['ftp'], ct.DOMAINS['idxip'],
# ct.PAGES['zz500b']), parse_cols=[0,1])
# df.columns = ct.FOR_CLASSIFY_B_COLS
# df['code'] = df['code'].map(lambda x :str(x).zfill(6))
wt = pd.read_excel(ct.HS300_CLASSIFY_URL_FTP%(ct.P_TYPE['ftp'], ct.DOMAINS['idxip'],
ct.PAGES['zz500wt']), parse_cols=[0, 3, 6])
wt.columns = ct.FOR_CLASSIFY_W_COLS
wt['code'] = wt['code'].map(lambda x :str(x).zfill(6))
df = get_stock_basics()[['name']]
df = df.reset_index()
return pd.merge(df,wt)
except Exception as er:
print(str(er))
示例8: test_get_stock_basics
def test_get_stock_basics(self):
print(fd.get_stock_basics())
示例9: bar2h5
def bar2h5(market='', date='', freq='D', asset='E', filepath=''):
cons = get_apis()
stks = get_stock_basics()
fname = "%s%s%sbar%s.h5"%(filepath, market, date, freq)
store = pd.HDFStore(fname, "a")
if market in ['SH', 'SZ']:
if market == 'SH':
stks = stks.ix[stks.index.str[0]=='6', :]
elif market == 'SZ':
stks = stks.ix[stks.index.str[0]!='6', :]
else:
stks = ''
market = 1 if market == 'SH' else 0
for stk in stks.index:
symbol = '%s.SH'%stk
if 'min' in freq:
df = bar(stk, conn=cons, start_date=date, end_date=date, freq=freq,
market=market, asset=asset)
df['Time'] = df.index
df['Time'] = df['Time'].apply(get_dt_time)
df.index = df['Time']
df.drop(['code','Time'], axis = 1, inplace=True)
df.rename(columns={'open':'OPEN'}, inplace=True)
df.rename(columns={'close':'CLOSE'}, inplace=True)
df.rename(columns={'low':'LOW'}, inplace=True)
df.rename(columns={'high':'HIGH'}, inplace=True)
df.rename(columns={'vol':'VOLUME'}, inplace=True)
df.rename(columns={'amount':'TURNOVER'}, inplace=True)
df.loc[:,'HIGH'] = df.loc[:,'HIGH'].astype("int64")
df.loc[:,'LOW'] = df.loc[:,'LOW'].astype("int64")
df.loc[:,'OPEN'] = df.loc[:,'OPEN'].astype("int64")
df.loc[:,'CLOSE'] = df.loc[:,'CLOSE'].astype("int64")
df.loc[:,'VOLUME'] = df.loc[:,'VOLUME'].astype("int64")
df.loc[:,'TURNOVER'] = df.loc[:,'TURNOVER'].astype("int64")
df.loc[:,'OPEN'] *= 10000
df.loc[:,'CLOSE'] *= 10000
df.loc[:,'HIGH'] *= 10000
df.loc[:,'LOW'] *= 10000
df.loc[:,'ASKPRICE1'] = 0
df.loc[:,'ASKPRICE2'] = 0
df.loc[:,'ASKPRICE3'] = 0
df.loc[:,'ASKPRICE4'] = 0
df.loc[:,'ASKPRICE5'] = 0
df.loc[:,'ASKPRICE6'] = 0
df.loc[:,'ASKPRICE7'] = 0
df.loc[:,'ASKPRICE8'] = 0
df.loc[:,'ASKPRICE9'] = 0
df.loc[:,'ASKPRICE10'] = 0
df.loc[:,'BIDPRICE1'] = 0
df.loc[:,'BIDPRICE2'] = 0
df.loc[:,'BIDPRICE3'] = 0
df.loc[:,'BIDPRICE4'] = 0
df.loc[:,'BIDPRICE5'] = 0
df.loc[:,'BIDPRICE6'] = 0
df.loc[:,'BIDPRICE7'] = 0
df.loc[:,'BIDPRICE8'] = 0
df.loc[:,'BIDPRICE9'] = 0
df.loc[:,'BIDPRICE10'] = 0
df.loc[:,'ASKVOL1'] = 0
df.loc[:,'ASKVOL2'] = 0
df.loc[:,'ASKVOL3'] = 0
df.loc[:,'ASKVOL4'] = 0
df.loc[:,'ASKVOL5'] = 0
df.loc[:,'ASKVOL6'] = 0
df.loc[:,'ASKVOL7'] = 0
df.loc[:,'ASKVOL8'] = 0
df.loc[:,'ASKVOL9'] = 0
df.loc[:,'ASKVOL10'] = 0
df.loc[:,'BIDVOL1'] = 0
df.loc[:,'BIDVOL2'] = 0
df.loc[:,'BIDVOL3'] = 0
df.loc[:,'BIDVOL4'] = 0
df.loc[:,'BIDVOL5'] = 0
df.loc[:,'BIDVOL6'] = 0
df.loc[:,'BIDVOL7'] = 0
df.loc[:,'BIDVOL8'] = 0
df.loc[:,'BIDVOL9'] = 0
df.loc[:,'BIDVOL10'] = 0
df.loc[:,'VWAP'] = 0.0
df.loc[:,'VOL30']=0.0
df.loc[:,'TOTAL_VOLUME']=0.0
df.loc[:,'TOTAL_TURNOVER']=0.0
df.loc[:,'INTEREST']=0.0
print(df)
# if market == 1 and stk[0] == '6':
# df = bar(stk, conn=cons, start_date=date, end_date=date, freq=freq, market=market, asset=asset)
store[symbol] = df
store.close()
close_apis(cons)