From 37f8926c1c760de4e3ac3ba52624b24e73ee6db9 Mon Sep 17 00:00:00 2001 From: Paul Leclercq Date: Fri, 13 Sep 2024 10:36:56 +0200 Subject: [PATCH] refacto: dataframe loop with itertuples --- quotaclimat/data_processing/mediatree/api_import.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/quotaclimat/data_processing/mediatree/api_import.py b/quotaclimat/data_processing/mediatree/api_import.py index 6334c26a..d84119ae 100644 --- a/quotaclimat/data_processing/mediatree/api_import.py +++ b/quotaclimat/data_processing/mediatree/api_import.py @@ -103,16 +103,17 @@ async def get_and_save_api_data(exit_event): try: programs_for_this_day = get_programs_for_this_day(day, channel, df_programs) - for index, program in programs_for_this_day.iterrows(): - start_epoch = program['start'] - end_epoch = program['end'] - channel_program = str(program['program_name']) - channel_program_type = str(program['program_type']) + for program in programs_for_this_day.itertuples(index=False): + start_epoch = program.start + end_epoch = program.end + channel_program = str(program.program_name) + channel_program_type = str(program.program_type) logging.info(f"Querying API for {channel} - {channel_program} - {channel_program_type} - {start_epoch} - {end_epoch}") df = extract_api_sub(token, channel, type_sub, start_epoch,end_epoch, channel_program,channel_program_type) if(df is not None): logging.debug(f"Memory df {df.memory_usage()}") save_to_pg(df, keywords_table, conn) + del df else: logging.info("Nothing to save to Postgresql") gc.collect()