ts.set_token('')
import datetime
start='20160601'
end='20170101'
list1 = []
datestart=datetime.datetime.strptime(start,'%Y%m%d')
dateend=datetime.datetime.strptime(end,'%Y%m%d')
while datestart<dateend:
datestart+=datetime.timedelta(days=1)
print(datestart.strftime('%Y%m%d'))
d = datestart.strftime('%Y%m%d')
list1.append(d)pro = ts.pro_api()
from datetime import datetime, timedelta,date,time
data = pd.DataFrame()
for i in list1 :
df = pro.cctv_news(date='{}'.format(i))
df=df.groupby(['date'])['content'].apply(list).reset_index()
def date_chuli(x):
date_str = str(x)
fmt = '%Y%m%d'
time_tuple = datetime.strptime(date_str, fmt).strftime("%Y%m%d")
week = datetime.strptime('{}'.format(time_tuple),'%Y%m%d').weekday()+1
return week
df['week']=df['date'].apply(date_chuli)
data = data.append(df,ignore_index=True)
金融时间序列处理——(tushare新闻数据合并)添加星期
最新推荐文章于 2023-10-08 21:50:27 发布