-
https://docs.llamaindex.ai/en/stable/examples/agent/openai_agent_query_plan/ I like to use the example provided in the link. Instead of pdfs, I like to pass 3 pandas dataframes run the same process. Is that possible? Below I like to simulate to pandas dataframe instead of .pdf. Please help.
|
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 5 replies
-
To modify the provided code snippet to load Pandas DataFrames into a import pandas as pd
from llama_index.core.schema import Document
from llama_index.vector_stores.types import VectorStoreQueryResult
from llama_index.vector_stores.vearch.base import VearchVectorStore
from llama_index.legacy.indices.vector_store.base import VectorStoreIndex
# Sample DataFrames
march_2022_df = pd.DataFrame({
'text': ["March 2022 data point 1", "March 2022 data point 2"],
'metadata': ["meta1", "meta2"]
})
june_2022_df = pd.DataFrame({
'text': ["June 2022 data point 1", "June 2022 data point 2"],
'metadata': ["meta1", "meta2"]
})
sept_2022_df = pd.DataFrame({
'text': ["September 2022 data point 1", "September 2022 data point 2"],
'metadata': ["meta1", "meta2"]
})
# Function to convert DataFrame to Document list
def df_to_documents(df):
return [Document(text=row['text'], metadata=row.to_dict()) for _, row in df.iterrows()]
# Convert DataFrames to Document lists
march_2022_docs = df_to_documents(march_2022_df)
june_2022_docs = df_to_documents(june_2022_df)
sept_2022_docs = df_to_documents(sept_2022_df)
# Create VectorStoreIndex from Document lists
march_index = VectorStoreIndex.from_documents(march_2022_docs)
june_index = VectorStoreIndex.from_documents(june_2022_docs)
sept_index = VectorStoreIndex.from_documents(sept_2022_docs) This code snippet demonstrates how to convert each DataFrame into a list of |
Beta Was this translation helpful? Give feedback.
-
@dosu Is the text column in the example similar to an 'index' of the dataframe? I'm still new to this and want to understand the basics. Thank you for your patience! Also, once I vectorize my pandas dataframe, can I save those vectors in a Chroma vector database? Sorry for all the questions... I'm trying to figure out how we can best use the 'llamaindex' package for structured data insights. Thanks again! |
Beta Was this translation helpful? Give feedback.
The
text
column in the example is not the same as the DataFrame's index. Instead, it is a column that contains the text data you want to convert intoDocument
objects. The DataFrame's index is a separate entity that uniquely identifies each row, while thetext
column holds the actual content of the documents.To save the vectorized DataFrame in a Chroma vector database, you can follow these steps:
Convert the DataFrame to a list of
Document
objects: