Chat with your database (SQL, CSV, pandas, polars, mongodb, noSQL, etc). PandasAI makes data analysis conversational using LLMs (GPT 3.5 / 4, Anthropic, VertexAI) and RAG.
The bug is PandasConnector isn't well-linked to a Pandas Dataframe, as error message below, running generated code to manipulate df raise error.
The user asked the following question:
QUERY
德州仪器中工作温度相同的芯片有哪些
You generated this python code:
import pandas as pd
Assuming the DataFrame provided is already given to us as df.
df = dfs[0]
Filter the DataFrame for Texas Instruments
texas_instruments_df = df[df['制造商'] == 'Texas Instruments']
Ensure that we only consider rows where temperature values are not NaN
texas_instruments_df = texas_instruments_df.dropna(subset=['最小工作温度', '最大工作温度'])
Group by unique combinations of minimum and maximum working temperature
grouped_by_temp_df = texas_instruments_df.groupby(['最小工作温度', '最大工作温度'])
Extract groups with more than one entry (the same working temperature range)
common_temp_chips = {}
for (min_temp, max_temp), group in grouped_by_temp_df:
if len(group) > 1:
common_temp_chips[f"{min_temp}C to {max_temp}C"] = group['零件型号'].tolist()
Convert dictionary to DataFrame for better readability
common_temp_chips_df = pd.DataFrame([(k, v) for k, v in common_temp_chips.items()], columns=['Temperature Range', 'Chip Models'])
Showing the result
print(common_temp_chips_df)
It fails with the following error:
Traceback (most recent call last):
File "/root/anaconda3/envs/chatdb/lib/python3.9/site-packages/pandasai/pipelines/chat/code_execution.py", line 64, in execute
result = code_manager.execute_code(code_to_run, code_context)
File "/root/anaconda3/envs/chatdb/lib/python3.9/site-packages/pandasai/helpers/code_manager.py", line 182, in execute_code
code_to_run = self._clean_code(code, context)
File "/root/anaconda3/envs/chatdb/lib/python3.9/site-packages/pandasai/helpers/code_manager.py", line 562, in _clean_code
self._extract_fix_dataframe_redeclarations(node, clean_code_lines)
File "/root/anaconda3/envs/chatdb/lib/python3.9/site-packages/pandasai/helpers/code_manager.py", line 467, in _extract_fix_dataframe_redeclarations
exec(code, env)
File "", line 3, in
TypeError: 'PandasConnector' object is not subscriptable
System Info
pandasai==2.0.21 pytho==3.9.19 os==ubuntu
🐛 Describe the bug
The bug is PandasConnector isn't well-linked to a Pandas Dataframe, as error message below, running generated code to manipulate df raise error.
The user asked the following question: QUERY 德州仪器中工作温度相同的芯片有哪些
You generated this python code: import pandas as pd
Assuming the DataFrame provided is already given to us as df. df = dfs[0]
Filter the DataFrame for Texas Instruments texas_instruments_df = df[df['制造商'] == 'Texas Instruments']
Ensure that we only consider rows where temperature values are not NaN texas_instruments_df = texas_instruments_df.dropna(subset=['最小工作温度', '最大工作温度'])
Group by unique combinations of minimum and maximum working temperature grouped_by_temp_df = texas_instruments_df.groupby(['最小工作温度', '最大工作温度'])
Extract groups with more than one entry (the same working temperature range) common_temp_chips = {} for (min_temp, max_temp), group in grouped_by_temp_df: if len(group) > 1: common_temp_chips[f"{min_temp}C to {max_temp}C"] = group['零件型号'].tolist()
Convert dictionary to DataFrame for better readability common_temp_chips_df = pd.DataFrame([(k, v) for k, v in common_temp_chips.items()], columns=['Temperature Range', 'Chip Models'])
Showing the result print(common_temp_chips_df)
It fails with the following error: Traceback (most recent call last): File "/root/anaconda3/envs/chatdb/lib/python3.9/site-packages/pandasai/pipelines/chat/code_execution.py", line 64, in execute result = code_manager.execute_code(code_to_run, code_context) File "/root/anaconda3/envs/chatdb/lib/python3.9/site-packages/pandasai/helpers/code_manager.py", line 182, in execute_code code_to_run = self._clean_code(code, context) File "/root/anaconda3/envs/chatdb/lib/python3.9/site-packages/pandasai/helpers/code_manager.py", line 562, in _clean_code self._extract_fix_dataframe_redeclarations(node, clean_code_lines) File "/root/anaconda3/envs/chatdb/lib/python3.9/site-packages/pandasai/helpers/code_manager.py", line 467, in _extract_fix_dataframe_redeclarations exec(code, env) File "", line 3, in
TypeError: 'PandasConnector' object is not subscriptable