python 跑指标模板 时间段 id数

python经常要跑指标或其他相关时,需要取id及日期:
不同储存方式提供了不同的取法,可以专门总结一下:

#跑excel模板
df=pd.read_excel('重算指标的ID.xlsx',header=None,converters={0:str})
    for i, row in df.iterrows():
        print(row[0])
        dates = pd.date_range('20220901','20221015').strftime('%Y-%m-%d').tolist()
        gmIndicatorCal = GmIndicatorCal(fund_id=row[0], engine_url=engine().url)
        
        for date in dates:
            print(date)
            result = gmIndicatorCal.cal(date, 'd')

    #跑时间段模板
    for id in ['121008','12100','519800','519899']:
        print(id)
        dates = pd.date_range('2022-12-20', dt.datetime.now()).strftime('%Y-%m-%d').tolist()
        gmIndicatorCal = GmIndicatorCal(fund_id=id, engine_url=engine().url)
        for date in dates:
            print(id,date)
            result = gmIndicatorCal.cal(date, 'd')


    #跑sql模板
    sql="""SELECT fund_id,statistic_date FROM some_tables"""
    df=pd.read_sql(sql,engine())
    print(df)

    for i,my_data in df.iterrows():
        id=my_data['fund_id']
        date=my_data['statistic_date'].strftime('%Y-%m-%d')
        print(id, date)
        gmIndicatorCal = GmIndicatorCal(fund_id=id, engine_url=engine().url)
        result = gmIndicatorCal.cal(date, 'd')


    #跑sql 时间段模板
    sql="""SELECT  fund_id,MIN(statistic_date)  from some_tables  GROUP BY fund_id"""
    df=pd.read_sql(sql,engine())
    print(df)

    for i,my_data in df.iterrows():
        id=my_data['fund_id']
        date=my_data['MIN(statistic_date)'].strftime('%Y-%m-%d')

        dates = pd.date_range(date, dt.datetime.now()).strftime('%Y-%m-%d').tolist()
        gmIndicatorCal = GmIndicatorCal(fund_id=id, engine_url=engine().url)
        for date in dates:
            print(id,date)
            result = gmIndicatorCal.cal(date, 'd')

你可能感兴趣的:(python,python,数据库,sql)