preprocess.py 文件源码

python
阅读 27 收藏 0 点赞 0 评论 0

项目:Book_DeepLearning_Practice 作者: wac81 项目源码 文件源码
def get_open_close_hist_price(code, start_date=None, end_date=None):
    '''
    :param code: ????
    :param date: ??????
    :return: ?????open close ???
    '''
    import tushare as ts
    if start_date != None and end_date != None:

        if type(code) is not str or type(start_date) is not str:
            code = str(code)
            start_date = str(start_date)
            end_date = str(end_date)



        df = ts.get_hist_data(code, start_date,end_date)
        df = df.head(1)
        dtime = df.set_index('time')
        price = dtime['price']
        if price.shape == (0,):
            print code, "can't get ", start_date, "am_pm data!"
            return float('nan'), float('nan')
        else:
            return price[-1], price[len(df.time)/4]

    else:
        df = ts.get_hist_data(code)
        df = df.head(1)
        dtime = df.set_index('time')
        price = dtime['price']
        if price.shape == (0,):
            print code, "can't get ", start_date, "am_pm data!"
            return float('nan'), float('nan')
        else:
            return price[-1], price[len(df.time)/4]
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号