# Using Pandas to create a Q&A chatbot

**URL:** <https://discuss.huggingface.co/t/using-pandas-to-create-a-q-a-chatbot/40748>\
**Category:** Beginners\
**Created:** [May 23, 2023, 3:31pm UTC](https://discuss.huggingface.co/t/using-pandas-to-create-a-q-a-chatbot/40748 "2023-05-23T15:31:22Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![kamiyan89](https://avatars.discourse-cdn.com/v4/letter/k/d78d45/32.png) [@kamiyan89](https://discuss.huggingface.co/u/kamiyan89)\
**Post date:** [May 23, 2023, 3:31pm UTC](https://discuss.huggingface.co/t/using-pandas-to-create-a-q-a-chatbot/40748/1 "2023-05-23T15:31:23Z")

</div>

Hi everyone

Currently I have a Database with Questions on column A and answers on column B.

I Want to create a chatbot that takes the user’s question, searches the most similar question on Column A and outputs its correspondent answer.

I tried doing this with Vector, keyword and tree indexes. but when I ask for example question 1, it outputs answer 2.  
or sometimes it combines answer 1 and 3 for example.

![image](https://us1.discourse-cdn.com/hellohellohello/original/3X/b/c/bc780bb55feccba3603fae38381c230423bbb996.png)

I tried to create a pandas index and it works very well only if the user’s question is exactly the same as a question from column A.

if i change a word only a little, an error appears and says that I am trying to look outside the range of the table.

So my question is:

Is a pandas index the right index for this kind of cases?  
if not? what is the most suited index format in this case? and how can I ensure to reply always right?

my code for the pandas index is:

````auto
import logging
import sys
import os
logging.basicConfig(stream=sys.stdout, level=logging.INFO)
logging.getLogger().addHandler(logging.StreamHandler(stream=sys.stdout))

from llama_index import SimpleDirectoryReader
from IPython.display import Markdown, display

from llama_index.indices.struct_store import GPTPandasIndex
import pandas as pd

os.environ["OPENAI_API_KEY"] = ''

col_names = ['Question','Answer']
df = pd.read_csv("Q&A.csv", names = col_names)
df.reset_index(inplace = True)
index = GPTPandasIndex(df=df)

query_engine = index.as_query_engine(
    verbose=True
)
response = query_engine.query(
    "/question from my database",
)
print (response)```
````
