#iterrows练习
#纪念lambda鲜有的顺手写出来,难得这么pythonic...
#最后的最后,挑出连续停牌的方式,值得黄鱼脑袋留念...
for stock in stock_list:
re_ordered = []
res_of_lists = []
list_contig = []
listed_date = instruments(stock).listed_date
status_str = instruments(stock).status
if (listed_date != '2999-12-31' and (listed_date != '0000-00-00') and (status_str=='Active')) : #处理有效股票(具备上市日期)
try:
suspension_true_df = is_suspended(stock) #得到公司上市每个日期的停牌情况
except:
continue
for index,row in suspension_true_df.iterrows():
if row[0] == True:
list_contig.append(index) #放到临时list里面
else:
if len(list_contig) > 1:
res_of_lists.append(list_contig) #放到大的list里面
list_contig = [] #清空临时
list_contig = []
re_ordered = list(filter(lambda x : len(x) > 1 ,res_of_lists)) #再次确保得到了连续的停牌
res_of_lists = []
total_consequent = 0
total_consequent = len(re_ordered)
for k in range(total_consequent):
df_close = get_price(stock,start_date=re_ordered[k][0],end_date=re_ordered[k][-1])
if not df_close is None:
list_close = list(df_close.close)
verifying = list(set(list_close))
if len(verifying) == 2 and (round(verifying[0],2) != round(verifying[1],2)):
print(stock,re_ordered[k][0],re_ordered[k][-1])
elif len(verifying) > 2:
print(stock,"more than 2",re_ordered[k][0],re_ordered[k][-1])
else:
continue