1 if not p1.empty: 2 pass 3 else: 4 p1_weekend = datetime.fromtimestamp(unix-unix_weekend).strftime("%Y-%m-%d") 5 p1 = get_price(index[each],start_date = p1_weekend,end_date = p1_weekend,frequency = "daily",fields = "close")
1、if df.empty:可以判断df是否为空,可以用来过滤数据获取失败的情况。
2、datetime.fromtimestamp(unix-unix_weekend).strftime("%Y-%m-%d"),timestamp转换字符串格式可以用timestamp减去三天的秒数获得三天前的时间
date_stamp = datetime.strptime(date[each],"%Y-%m-%d") unix = time.mktime(date_stamp.timetuple())
可以用上面代码将str转化成timestamp