Prompt Title: Loop Result Collection.

Created 9 months ago
Votes 0
Views 121 times
0
Human: <div class="empty:hidden">why this for loop only keep the last iteration? if run_supply_insights: # Read the questions dataset df_supply_insights_questions = pd.read_csv(supply_insights_questions) for row in range(2): # Split the text into smaller chunks supply_insights_docs = text_splitter.create_documents([df_supply_insights.loc[row]['slack_message']]) for supply_doc in supply_insights_docs: supply_doc.metadata['supplier_name'] = df_supply_insights.loc[row]['supplier_name'] supply_doc.metadata['raw_text'] = df_supply_insights.loc[row]['slack_message'] # Create a new database based on this documents new_db = create_chromadb_vectorstore(document_list=supply_insights_docs) llm_parser = DiscoveryLLMParser(vectorstore = new_db) df_supply_insights_questions[['structured_output', 'raw_answer']] = df_supply_insights_questions.apply(get_structured_output, axis=1, result_type='expand') df_supply_insights_questions['name'] = df_supply_insights.loc[row]['supplier_name'] df_supply_insights_questions['text'] = df_supply_insights.loc[row]['slack_message']</div>
ChatGPT:

The provided code snippet contains a for loop that iterates over the range of numbers [0, 1] (since range(2) generates [0, 1]). As a result, the loop will only execute twice, once for row = 0 and once for row = 1.

In each iteration of the for loop, the code performs various operations on supply_insights_docs and eventually creates a new database new_db. The issue is that new_db is overwritten in each iteration, so only the last iteration's value of new_db will be retained, and the previous ones will be lost.

If the intention is to keep the results for all iterations, you need to modify the code to store the results from each iteration in a collection (e.g., a list) instead of overwriting the same variable. For example:

python
if run_supply_insights: df_supply_insights_questions = pd.read_csv(supply_insights_questions) supply_insights_results = [] # Create an empty list to store results for row in range(2): supply_insights_docs = text_splitter.create_documents([df_supply_insights.loc[row]['slack_message']]) for supply_doc in supply_insights_docs: supply_doc.metadata['supplier_name'] = df_supply_insights.loc[row]['supplier_name'] supply_doc.metadata['raw_text'] = df_supply_insights.loc[row]['slack_message'] new_db = create_chromadb_vectorstore(document_list=supply_insights_docs) llm_parser = DiscoveryLLMParser(vectorstore=new_db) df_supply_insights_questions[['structured_output', 'raw_answer']] = df_supply_insights_questions.apply(get_structured_output, axis=1, result_type='expand') df_supply_insights_questions['name'] = df_supply_insights.loc[row]['supplier_name'] df_supply_insights_questions['text'] = df_supply_insights.loc[row]['slack_message'] supply_insights_results.append(df_supply_insights_questions.copy()) # Store the results for this iteration # Now you have all the results from each iteration in supply_insights_results list

With this modification, supply_insights_results will contain the results for each iteration of the loop, preserving the data from all iterations.

avatar
elias prost
Shared 1 prompt
Created 9 months ago

Leave a Comment

Related Tag Prompts

271
0
Python Pro
1 year ago 2023-01-19 05:16:28 AIPRM
0
0
MySQL Database Creation.
1 year ago 2023-03-08 12:23:48 Pub
0
0
Cool stuff
1 year ago 2023-03-08 15:49:26 Sivayogeith
0
0
Bajar version de python
1 year ago 2023-03-09 10:48:33 Juanma
0
0
Frappe
1 year ago 2023-03-11 01:40:59 KuuKuu
0
0
0
0
python remote control server
1 year ago 2023-03-11 23:05:25 V0rt
0
0
output
1 year ago 2023-03-14 07:09:17 yuvaraj
0
0
s-parameter processing in python
1 year ago 2023-03-14 14:46:13 jhdo
0
0
Python Landsat data handling.
1 year ago 2023-03-15 13:10:40 nathan
0
0
Python para Ciencia Datos
1 year ago 2023-03-16 08:24:10 pedro
0
0
Following Rotated Logfiles.
1 year ago 2023-03-17 09:05:24 hamid
0
0
Modelo de Negócio.
1 year ago 2023-03-18 01:35:57 reiu
0
0
Django API for Todo
1 year ago 2023-03-18 17:45:33 AbdAlmjed
0
0
python爬虫
1 year ago 2023-03-21 00:23:14 DDL
0
0
Improvment_product_generator
1 year ago 2023-03-21 10:01:17 Matěj Konečný