def save_income_df_to_db(engine, dataframe ): #pd.set_option('display.max_columns', 200) #pd.reset_option('display.max_columns') a = nr.clean_df_db_dups(dataframe, 'Income', engine, ['id'] ) a.to_sql( 'Income', con = engine , index=False, if_exists='append')
def save_XrXd_df_to_db(engine, df): ##conn = engine.connect() ##trans = conn.begin() ##try: ## start_d = '%d-01-01' % year ## end_d = '%d-01-01' % (year +1) ## s = alch_text( ## ''' ## delete from XrXd ## where report_date between :A and :B ## ''' ## ) ## conn.execute( s, A = year, B = compo_m ) ## ## trans.commit() ##except Exception as e: ## trans.rollback() ## raise e ## 我们只关心‘已经实施’的分红除权记录,而‘已经实施’的记录是不会再变的,因此无须删除DB里原有记录 a = nr.clean_df_db_dups(df ,'XrXd', engine, ['id'] ) a.to_sql( 'XrXd', con = engine , index=False, if_exists='append')
def save_valuation_df_to_db(engine, dataframe ): if dataframe is None: return #pd.set_option('display.max_columns', 200) #pd.reset_option('display.max_columns') a = nr.clean_df_db_dups(dataframe, 'Valuation', engine, ['id'] ) a.to_sql( 'Valuation', con = engine , index=False, if_exists='append')
def save_balance_df_to_db(engine, dataframe ): #pd.set_option('display.max_columns', 200) # a = dataframe.drop( 'statDate.1' , axis =1 ) # 这列文档里没有 #pd.reset_option('display.max_columns') a = nr.clean_df_db_dups(dataframe ,'BalanceSheetDay', engine, ['id'] ) a.to_sql( 'BalanceSheetDay', con = engine , index=False, if_exists='append')
def save_daily_line_to_db(engine, code, dataframe ): #pd.set_option('display.max_columns', 200) #pd.reset_option('display.max_columns') if dataframe is None: return a= dataframe a.insert(0, 'code', code) # 加一列'code',都设为code a['t_day'] = a.index # 加一列't_day',设为该行的index,也就是 datetime64 a['t_day'] = a['t_day'].apply(date_only) # 对于所有行的't_day'列,执行一次'date_only'函数 #print a a = nr.clean_df_db_dups(a , 'DailyLine', engine, ['code', 't_day'] ) a.to_sql( 'DailyLine', con = engine , index=False, if_exists='append')
def save_forcast_df_to_db(engine, df): a = nr.clean_df_db_dups(df ,'Forcast', engine, ['id'] ) a.to_sql( 'Forcast', con = engine , index=False, if_exists='append')