|
import pandas as pd
import glob
import os
os.chdir('path/stock_hfqqa')
summ=pd.DataFrame()
for file in glob.glob('*.csv'):
fname='.'.join(file.split('.')[0:2])
df=pd.read_csv(file,dtype={'trade_date':'str'})
df['trade_date']=pd.to_datetime(df['trade_date'])
df['year']=df['trade_date'].dt.year
min_row=df[df['year']==2020]['close'].idxmin()
end_date_min=df.iloc[min_row]['trade_date']
start_date_min=end_date_min-pd.Timedelta(days=100)
mindf=df.loc[(df['trade_date']>=start_date_min) & (df['trade_date']<=end_date_min)]
tempdf=mindf.head(1).copy()
tempdf['date_start']=start_date_min
summ=summ.append(tempdf,ignore_index=True)
filemin=fname+'_min'+'.xlsx'
mindf.to_excel(filemin,index=False)
max_row=df[df['year']==2020]['close'].idxmax()
end_date_max=df.iloc[max_row]['trade_date']
start_date_max=end_date_max-pd.Timedelta(days=100)
maxdf=df.loc[(df['trade_date']>=start_date_max) & (df['trade_date']<=end_date_max)]
tempdf=maxdf.head(1).copy()
tempdf['date_start']=start_date_max
summ=summ.append(tempdf,ignore_index=True)
filemax=fname+'_max'+'.xlsx'
maxdf.to_excel(filemax,index=False)
summ=summ[['ts_code','date_start','trade_date','close']]
summ.columns=['ts_code','date_start','date_end','close']
summ.to_excel('bbbb.xlsx',index=False)
|
|