Home > other >  Tushare crawl restricted lifted shares (by month)
Tushare crawl restricted lifted shares (by month)

Time:12-03

"" "
2020.12.01
As a function of encapsulation
"" "
The import pandas as pd
The import tushare as ts


Def data_get (date) :
Token='cf5e9df84cde5b1246db7dc1ba08d36d2e4a7760f6f078fc4c4b823c'
Pro=ts. Pro_api (token)
DFX=pro. Share_float (float_date=date)
Return DFX


Def func () :
The date=20201201
Df=data_get (date)
Df1=pd. DataFrame (df) ts_code) STR [0-6])
New_stock=df1) [r]. 'ts_code drop_duplicates ()
New_stock. To_excel (' 003. XLSX, encoding="utf-8")
Df2=pd. DataFrame (pd. Read_excel (' 003. XLSX, sheet_name='Sheet1'))
Df3=pd. DataFrame (pd. Read_excel (' C: \ \ Users \ \ SINBAD \ \ Desktop \ \ all_Astock XLSX ', sheet_name='Sheet1'))
Df_merge=pd. The merge (df2, df3, how='inner', on='ts_code')
Df_merge. Head ()
Df_merge. To_excel (' F: \ \ restricted lifted \ \ 20201201. XLSX ', sheet_name='Sheet1', the index=False)

Try:
For I in range (1, 29) :
Df4 axle=pd. DataFrame (pd. Read_excel (' F: \ \ restricted lifted \ \ 20201201. XLSX ', sheet_name='Sheet1'))
The date +=1
Df_=data_get (date)
Df1_=pd. DataFrame (df_. Ts_code. STR [0-6])
New_stock_=df1_ [' ts_code] drop_duplicates ()
New_stock_. To_excel (' 003. XLSX, encoding="utf-8")
Df2_=pd. DataFrame (pd. Read_excel (' 003. XLSX, sheet_name='Sheet1'))
Df_merge_=pd. The merge (df2_, df3, how='inner', on='ts_code')
Df_merge_. Head ()
Df_merge_merge_=pd. The merge (df4 axle, df_merge_, how='outer')
Df_merge_merge_. To_excel (' F: \ \ restricted lifted \ \ 20201201. XLSX ', sheet_name='Sheet1', the index=False)
I +=1
The else:
Print (' finish ')
Except:
Print (' byebye ')


If __name__=="__main__ ':
Func ()
 
  • Related