快速獲取可轉(zhuǎn)債信息,這里有最全的方法——python量化
三種方法獲取可轉(zhuǎn)債數(shù)據(jù)
1、通過 akshare 庫的“ak.bond_cb_jsl(cookie=cookie)”函數(shù)調(diào)取
2、通過 efinance 庫的“ef.bond.get_realtime_quotes()”函數(shù)調(diào)取—— efinance · PyPI
3、通過集思錄 api 爬取數(shù)據(jù),然后進(jìn)行數(shù)據(jù)處理
數(shù)據(jù)清洗
1、對索引進(jìn)行重命名
df?=?df.rename(columns={'cell.bond_id':?'代碼','cell.bond_nm':'簡稱'})
2、刪除特定的列
df?=?df.drop(columns=['id'])
3、保留相應(yīng)列的數(shù)據(jù)
df?=?df?[['代碼','簡稱']]
視頻中的代碼
import?akshare?as?ak import?pandas?as?pd cookie="你的cookie" #?通過akshare提供的庫獲取可轉(zhuǎn)債數(shù)據(jù) #?stock_zh_a_spot_em_df?=?ak.bond_cb_jsl(cookie=cookie) #?通過efinance提供的庫獲取可轉(zhuǎn)債數(shù)據(jù) import?efinance?as?ef #?print(ef.bond.get_realtime_quotes()) #?通過集思錄api獲取可轉(zhuǎn)債數(shù)據(jù) import?requests def?get_cb_data(): ??headers_jsl={'User-Agent':'Mozilla/5.0?(Windows?NT?10.0;?Win64;?x64;?rv:94.0)?Gecko/20100101?Firefox/94.0',?'Cookie':?cookie} ??url='https://www.jisilu.cn/data/cbnew/cb_list_new/?___jsl=LST___t=1637410410639' ??response?=?requests.get(url,headers=headers_jsl) ??data?=?response.json() ??df?=?pd.json_normalize(data['rows']) ??#?df?=?df.rename(columns={'cell.bond_id':?'代碼','cell.bond_nm':'簡稱'})??????#對索引進(jìn)行重命名 ??#?df?=?df.drop(columns=['id'])?#?刪除特定的列 ??#?df?=?df[['代碼','簡稱']]?#?保留的數(shù)據(jù) ??return?df #?print(get_cb_data()) #?get_cb_data().to_csv('可轉(zhuǎn)債測試.csv',?index=False)
#可轉(zhuǎn)債 #數(shù)據(jù)獲取 #數(shù)據(jù)清洗 #Python編程 #量化投資