Replies: 3 comments
-
To avoid modifying the original DataFrame when using PandasAI, you can create a copy of the DataFrame before performing any operations. This ensures that the original data remains unchanged. Here's how you can modify the code to work with a copy: # Create a copy of the original DataFrame
df_copy = df.copy()
# Convert the 'date' column to datetime format and set it as the index
df_copy['date'] = pd.to_datetime(df_copy['date'])
df_copy.set_index('date', inplace=True)
# Sort the DataFrame by date
df_copy.sort_index(inplace=True)
# Drop any rows with missing values
df_copy = df_copy.dropna()
# Extract the 'close' prices for analysis
close_prices = df_copy['close'] By using To continue talking to Dosu, mention @dosu. Help Dosu learn! Give it feedback: Great Response | Irrelevant Answer | Incorrect Sources | Too Verbose | Hallucination | Other |
Beta Was this translation helpful? Give feedback.
-
but the code generated by agent , not me |
Beta Was this translation helpful? Give feedback.
-
@XJTU-JP can you share more details about the context in which the agent generates this code? |
Beta Was this translation helpful? Give feedback.
-
System Info
pandasai 2.4.0
🐛 Describe the bug
This is the data that is input to the agent
![image](https://private-user-images.githubusercontent.com/85154110/395066715-e720db07-8e52-4e4b-a2c9-33f28859126d.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MzkxNzIxMjIsIm5iZiI6MTczOTE3MTgyMiwicGF0aCI6Ii84NTE1NDExMC8zOTUwNjY3MTUtZTcyMGRiMDctOGU1Mi00ZTRiLWEyYzktMzNmMjg4NTkxMjZkLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAyMTAlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMjEwVDA3MTcwMlomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWNjMDE2NjAyOWFkMTFiMmVlZWQwNDAyMzM5MzVmOWYyOGE1NTUyYzg1ODAzNTQ4M2JjNzcyYzg2YTJmN2NlYzImWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.Txce1FkKV2DnzHVZjWeyd0Ma7Szkm9lUmFpVftUXZYs)
then the agent run this code:
The original data is modified.
![image](https://private-user-images.githubusercontent.com/85154110/395068364-4795b306-8756-437f-bccc-f531cf07fa6d.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MzkxNzIxMjIsIm5iZiI6MTczOTE3MTgyMiwicGF0aCI6Ii84NTE1NDExMC8zOTUwNjgzNjQtNDc5NWIzMDYtODc1Ni00MzdmLWJjY2MtZjUzMWNmMDdmYTZkLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAyMTAlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMjEwVDA3MTcwMlomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTkzNWEwODBhYWQ1MDUwOTA2NzE1ZDA0YThiNDY0YThjOGY4NzEwNjI1OGRmODE5OTZlNWFjZTRjMDEwM2RiN2UmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.jM2J8XM4pgoiYPAt4WWax9OuvG3QULCnxX2AKYDkzq8)
How to avoid this problem
Beta Was this translation helpful? Give feedback.
All reactions