The code table in the field, the feeling of water is very deep

Code table in the field, I feel the water is deep

I wrote a little crawler that crawls the code table, a long time ago
Now I want to analyze it carefully, the classification of the code, and write a statistical function. Separately count the
7 codes with different prefixes, how many varieties are there.

First serving:

Code execution result:
Share pictures

and then reappear on the cooking art

def get_codelist(): cn_dict = p_load(' d:/db/amipy/data/codename_dict.pkl') lst = [c for c in cn_dict.keys()] lst.sort() return lstdef get_xzt_security_num(codelist,xzt='1'): u''' search Code list, get the number of varieties with the prefix '1' >>> codelist = get_codelist() >>> get_xzt_security_num(codelist, '0')''' count = 0 for c in codelist: if c.startswith(xzt) : count +=1 return countdef stats_security_num(codelist, dt='2018-03-01'): u''' respectively count the number of code types of a prefix. Examples: >>> clist = get_codelist() >> > stats_security_num(clist)''' print('The collection date of the securities code list of the Shanghai and Shenzhen stock markets:', dt) print('Number of securities in both market: {)'.format(len(codelist))) # 4237 prefix = ['0', '1', '2', '3', '5', '6', '9',] nums=[] total=0 for pre in prefix: num=get_xzt_security_num(codelist , pre) nums.append(num) total += num print("In the Shanghai and Shenzhen markets, the total number of securities varieties is: ", total) for i in range(len(nums)): print('Shanghai and Shenzhen two In the market, the number of securities with the prefix "{}" is: {}'.format(prefix[i], nums[i]))

and by the way: How to start the Ipython environment in the cmd window:

share picture

Leave a Comment

Your email address will not be published.