''' 2020.2.5 通过对2.3大跌后反弹情况,分析各股的市场认可度。 共2列保存到fantan.csv中,code为股票代码,val为0-100的分值 ''' import pandas as pd df=get_all_securities() #print(list(df['display_name'])) pr=get_price(list(df.index),count = 4, end_date='2020-02-05',frequency='daily',fields=['close'])['close'] #pr.columns=list(df['display_name']) #更改列名,转置后变index pr2=pr.T pr2['zf']=(pr2['2020-02-05'])/pr2['2020-01-23'] pr2['name']=df['display_name'] pr3=pr2[pr2['zf']>0].sort_values(by="zf" , ascending=False) pr3['num']=range(len(pr3)) pr3['val']=round((1-pr3['num']/len(pr3))*100,4) print(pr3.loc[:,['name','val']]) pr3.loc[:,['name','val']].to_csv('fantan.csv') #print(pr2[pr2['zf']>0.93])
结果形如:
name val 688026.XSHG 洁特生物 100.0000 688389.XSHG 普门科技 99.9735 688369.XSHG 致远互联 99.9470 002219.XSHE 恒康医疗 99.9205 600664.XSHG 哈药股份 99.8940 000652.XSHE 泰达股份 99.8675 600513.XSHG 联环药业 99.8411 300235.XSHE 方直科技 99.8146 300204.XSHE 舒泰神 99.7881 300051.XSHE 三五互联 99.7616
使用代码
import pandas as pd df=pd.read_csv("fantan.csv") df.columns=["code","name","val"] print(df[df["code"]=="688369.XSHG"])
输出
code name val 2 688369.XSHG 致远互联 99.947
处理的几点备忘:
1、给已有的dataframe的index命名,好难,没有好办法
2、只能从csv加载后,重新命名,查询用条件查