# How to make rasa chatbot Fetching csv file

**URL:** <https://forum.rasa.com/t/how-to-make-rasa-chatbot-fetching-csv-file/49250>\
**Category:** Feedback on Rasa Open Source\
**Created:** [November 15, 2021, 1:43pm UTC](https://forum.rasa.com/t/how-to-make-rasa-chatbot-fetching-csv-file/49250 "2021-11-15T13:43:51Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![dan246](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/dan246/32/16550_2.png) [@dan246](https://forum.rasa.com/u/dan246)\
**Post date:** [November 15, 2021, 1:43pm UTC](https://forum.rasa.com/t/how-to-make-rasa-chatbot-fetching-csv-file/49250/1 "2021-11-15T13:43:51Z")

</div>

I am building a Chinese chatbot for rasa

How can I make rasa read the answers in the csv?

My csv file looks like this:

question,answer

q1,answer1

q2,answer2

q3,answer3

…

When I said q1, let rasa answer answer 1

---

<div class="post-metadata">

**Author:** ![nik202](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/nik202/32/16098_2.png) [@nik202](https://forum.rasa.com/u/nik202)\
**Post date:** [November 15, 2021, 2:02pm UTC](https://forum.rasa.com/t/how-to-make-rasa-chatbot-fetching-csv-file/49250/2 "2021-11-15T14:02:36Z")

</div>

@dan246

Note: your excel file should have two fields i.e question | answer or what response you want to return but should be synchronized and even it should have variations of the question with answers.

@dan246 updated code on 23-Nov-2021

1. Please see this

2. When the above piece of code fetches the data i,e question part and make the faq.yml file of that data which you want to train and then later it will go into the second code that’s FuzzyWuzzy and then return your response. For me, it’s a clean process, but yes you need to fine-tune. Do try this code and search the FuzzyWuzzy process.

The advantage of this process is just added and run and that in excel/csv.

I hope this will solve your query and give you idea. Good Luck!

---

<div class="post-metadata">

**Author:** ![dan246](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/dan246/32/16550_2.png) [@dan246](https://forum.rasa.com/u/dan246)\
**Post date:** [November 15, 2021, 2:10pm UTC](https://forum.rasa.com/t/how-to-make-rasa-chatbot-fetching-csv-file/49250/3 "2021-11-15T14:10:09Z")

</div>

ok

let me try

thanks!!

---

<div class="post-metadata">

**Author:** ![nik202](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/nik202/32/16098_2.png) [@nik202](https://forum.rasa.com/u/nik202)\
**Post date:** [November 15, 2021, 2:10pm UTC](https://forum.rasa.com/t/how-to-make-rasa-chatbot-fetching-csv-file/49250/4 "2021-11-15T14:10:54Z")

</div>

@dan246 No worries, any time you are stuck please do tag me @ and nik202. I know you can do it. Good Luck!

---

<div class="post-metadata">

**Author:** ![dan246](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/dan246/32/16550_2.png) [@dan246](https://forum.rasa.com/u/dan246)\
**Post date:** [November 20, 2021, 4:04pm UTC](https://forum.rasa.com/t/how-to-make-rasa-chatbot-fetching-csv-file/49250/5 "2021-11-20T16:04:18Z")

</div>

@nik202 Hi, should I put the program in actions.py?

Because I noticed that there is a code similar to transcoding

which means I don’t need to fill in each piece of data with nlu, or do I need to set something?

---

<div class="post-metadata">

**Author:** ![nik202](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/nik202/32/16098_2.png) [@nik202](https://forum.rasa.com/u/nik202)\
**Post date:** [November 20, 2021, 4:10pm UTC](https://forum.rasa.com/t/how-to-make-rasa-chatbot-fetching-csv-file/49250/6 "2021-11-20T16:10:59Z")

</div>

@dan246 yes you need to mention the code in action.py as it and try run you will able to see the file. in data.

---

<div class="post-metadata">

**Author:** ![dan246](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/dan246/32/16550_2.png) [@dan246](https://forum.rasa.com/u/dan246)\
**Post date:** [November 20, 2021, 4:11pm UTC](https://forum.rasa.com/t/how-to-make-rasa-chatbot-fetching-csv-file/49250/7 "2021-11-20T16:11:02Z")

</div>

I am now extracting the data in the csv file like this:

![擷取](https://europe1.discourse-cdn.com/flex013/uploads/rasa/original/3X/8/5/8567dcab8ee3c43e362f40d955f9779c62466450.png)

(csv data)

use python to output ：

![擷取](https://europe1.discourse-cdn.com/flex013/uploads/rasa/original/3X/f/a/fa20c855b37024dc624a1df4d13b3aa27dfe2b39.png)

Then put it in rasa for training

---

<div class="post-metadata">

**Author:** ![nik202](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/nik202/32/16098_2.png) [@nik202](https://forum.rasa.com/u/nik202)\
**Post date:** [November 20, 2021, 8:41pm UTC](https://forum.rasa.com/t/how-to-make-rasa-chatbot-fetching-csv-file/49250/8 "2021-11-20T20:41:27Z")

</div>

@dan246 I will recommend to create a proper question answers ie.

file name for this is `faq_d.csv`

question |answer

How we can install rasa and rasa x | Please visit this link for installation [Installation Guide](https://rasa.com/docs/rasa-x/installation-and-setup/installation-guide/) How are the different types of slots | [Domain](https://rasa.com/docs/rasa/domain/#slot-types)

etc etc

When you run the above custom code, it will create the **faq.yml** file in the data folder which we will used to train our mode as we do manually and then you need a fuzzywuzzy logic to fetch the answers.

**Confirm me:**

1. Are you able to do this?
2. Do you understand this logic of fuzzywuzzy?

I’d would recommend to first do this process which I mentioned.

---

<div class="post-metadata">

**Author:** ![nik202](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/nik202/32/16098_2.png) [@nik202](https://forum.rasa.com/u/nik202)\
**Post date:** [November 20, 2021, 8:43pm UTC](https://forum.rasa.com/t/how-to-make-rasa-chatbot-fetching-csv-file/49250/9 "2021-11-20T20:43:47Z")

</div>

@dan246 can you explain more what you actually want?

The code I suggested will only create the intent and training examples, it will not create the domain and stories data.

---

<div class="post-metadata">

**Author:** ![dan246](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/dan246/32/16550_2.png) [@dan246](https://forum.rasa.com/u/dan246)\
**Post date:** [November 21, 2021, 1:18pm UTC](https://forum.rasa.com/t/how-to-make-rasa-chatbot-fetching-csv-file/49250/10 "2021-11-21T13:18:12Z")

</div>

@nik202What could we do to let the robot answer the question beyond the data we input though it had not be trained before, even if the answer is not correct at all

I know fuzzywuzzy, it’s hard for me, but I want to do it well

 ![1637501089254](https://europe1.discourse-cdn.com/flex013/uploads/rasa/original/3X/5/9/59e9a982afee30b104ee0e748847278137778120.jpeg)

(Second, the third sentence has not been trained, so the robot did not answer)

the robot can’t answer the qustion beyond its content and trainig examples. If it encounters the condition mentioned above, it just answer nothing. I hope it could answer the question beyond its content and trainig examples, even if the answer isn’t correct .

---

<div class="post-metadata">

**Author:** ![nik202](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/nik202/32/16098_2.png) [@nik202](https://forum.rasa.com/u/nik202)\
**Post date:** [November 21, 2021, 2:12pm UTC](https://forum.rasa.com/t/how-to-make-rasa-chatbot-fetching-csv-file/49250/11 "2021-11-21T14:12:29Z")

</div>

@dan246 how bot will answer the question which not reside in database (.csv) or training examples?

> [@dan246](#):
>
> (Second, the third sentence has not been trained, so the robot did not answer)

I dnt know your language.

I not get you what you try to do? and is code running which I suggested? Please confirm me that first.

---

<div class="post-metadata">

**Author:** ![dan246](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/dan246/32/16550_2.png) [@dan246](https://forum.rasa.com/u/dan246)\
**Post date:** [November 21, 2021, 3:05pm UTC](https://forum.rasa.com/t/how-to-make-rasa-chatbot-fetching-csv-file/49250/12 "2021-11-21T15:05:58Z")

</div>

@nik202 I put it in actions.py and trained rasa, but he did not run out of faq.yml

Do i need to add something else?

 ![1](https://europe1.discourse-cdn.com/flex013/uploads/rasa/original/3X/6/9/69959de1bea33f561d310df9095a6879b1737aad.png)

 ![擷取](https://europe1.discourse-cdn.com/flex013/uploads/rasa/original/3X/1/b/1b78f7e07ade92a9e01d3e69e061c1381576e76c.png)

---

<div class="post-metadata">

**Author:** ![nik202](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/nik202/32/16098_2.png) [@nik202](https://forum.rasa.com/u/nik202)\
**Post date:** [November 21, 2021, 10:15pm UTC](https://forum.rasa.com/t/how-to-make-rasa-chatbot-fetching-csv-file/49250/13 "2021-11-21T22:15:56Z")

</div>

@dan246 dan I thought you will mention this in action.py mate?

**Update code on 23-Nov-2021** @dan246

```auto
class GetAnswer(Action):
     def __init__ (self):
         self.faq_d = pd.read_csv('./data/faq_d.csv')
         qs = list(self.faq_d['question'])
         with open("./data/nlu/faq.yml", "wt", encoding="utf-8") as f:
             f.write('version: "2.0"\n')
             f.write("nlu: \n- intent: question\n examples: | \n")
             for q in qs:
                 f.write(f" - {q}\n") 

    def name(self) -> Text:
        return "action_get_answer"

        return []

```

and you need to mention `action_get_answer` in domain.yml too?

I can share you complete code and with running commands but it will kill your learning bro.

Try this please and then do let me know.

Hope you willl understand this. Thanks.

---

<div class="post-metadata">

**Author:** ![dan246](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/dan246/32/16550_2.png) [@dan246](https://forum.rasa.com/u/dan246)\
**Post date:** [November 22, 2021, 5:14pm UTC](https://forum.rasa.com/t/how-to-make-rasa-chatbot-fetching-csv-file/49250/14 "2021-11-22T17:14:10Z")

</div>

@nik202 hi,I’m sorry for the late response.

I tried the above method but still can’t succeed

I tried rasa shell and he ran the following error

 ![擷取](https://europe1.discourse-cdn.com/flex013/uploads/rasa/original/3X/6/2/621ceec03136832b4e27930dc9edc93b229e5654.png)

I checked rasa run actions

 ![擷取](https://europe1.discourse-cdn.com/flex013/uploads/rasa/original/3X/6/9/6964550f70444be2c073518d9a560a8bbdd53e4c.png)

I tried to find a solution by myself but failed 😭

Can you tell me how to improve? thank you

![擷取](https://europe1.discourse-cdn.com/flex013/uploads/rasa/original/3X/d/9/d992799fdea639b1a8bd55935cb713c7ff0b16ab.png)

 ![擷取](https://europe1.discourse-cdn.com/flex013/uploads/rasa/original/3X/5/e/5eb4ed0fc31a97706e63c81c7f2c2b3af93fec14.png)

---

<div class="post-metadata">

**Author:** ![nik202](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/nik202/32/16098_2.png) [@nik202](https://forum.rasa.com/u/nik202)\
**Post date:** [November 22, 2021, 5:35pm UTC](https://forum.rasa.com/t/how-to-make-rasa-chatbot-fetching-csv-file/49250/15 "2021-11-22T17:35:42Z")

</div>

@dan246 Dan check the indentation, can you put 1 space before

`def name(self) -> Text:`

It should be alined with above def

Try

---

<div class="post-metadata">

**Author:** ![nik202](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/nik202/32/16098_2.png) [@nik202](https://forum.rasa.com/u/nik202)\
**Post date:** [November 22, 2021, 5:37pm UTC](https://forum.rasa.com/t/how-to-make-rasa-chatbot-fetching-csv-file/49250/16 "2021-11-22T17:37:40Z")

</div>

![Screenshot 2021-11-22 at 5.33.13 PM](https://europe1.discourse-cdn.com/flex013/uploads/rasa/original/3X/a/c/acf7157d23a31347332685ce84813b9145b6edf2.png) ![Screenshot 2021-11-22 at 5.33.34 PM](https://europe1.discourse-cdn.com/flex013/uploads/rasa/original/3X/b/d/bdfb601f792f141597b63b465eafca39342b3e71.png) ![Screenshot 2021-11-22 at 5.33.59 PM](https://europe1.discourse-cdn.com/flex013/uploads/rasa/original/3X/e/a/ea1ee05dd76281ef97a8906ee854c5d6e92a5fa0.png)

To confirm code is running properly . Good Luck!

---

<div class="post-metadata">

**Author:** ![dan246](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/dan246/32/16550_2.png) [@dan246](https://forum.rasa.com/u/dan246)\
**Post date:** [November 23, 2021, 5:56am UTC](https://forum.rasa.com/t/how-to-make-rasa-chatbot-fetching-csv-file/49250/17 "2021-11-23T05:56:00Z")

</div>

@nik202 Good afternoon, it ran out of new errors 😢

 ![擷取](https://europe1.discourse-cdn.com/flex013/uploads/rasa/original/3X/f/4/f4c2f97e9d9425ef0bb49bc4a23160eeae672a81.png)Is my file format wrong?

Or am I not setting it somewhere?

---

<div class="post-metadata">

**Author:** ![nik202](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/nik202/32/16098_2.png) [@nik202](https://forum.rasa.com/u/nik202)\
**Post date:** [November 23, 2021, 12:06pm UTC](https://forum.rasa.com/t/how-to-make-rasa-chatbot-fetching-csv-file/49250/18 "2021-11-23T12:06:11Z")

</div>

@dan246 I have shared you everything bro, please share me the code again or just copy and paste it action.py file which I wrote and just run rasa run actions.

---

<div class="post-metadata">

**Author:** ![dan246](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/dan246/32/16550_2.png) [@dan246](https://forum.rasa.com/u/dan246)\
**Post date:** [November 23, 2021, 12:42pm UTC](https://forum.rasa.com/t/how-to-make-rasa-chatbot-fetching-csv-file/49250/19 "2021-11-23T12:42:46Z")

</div>

@nik202 sorry

 ![擷取](https://europe1.discourse-cdn.com/flex013/uploads/rasa/original/3X/b/c/bc75ad82bdb4cb6d3442804b0df6d81af4ce21e8.png) ![擷取](https://europe1.discourse-cdn.com/flex013/uploads/rasa/original/3X/8/5/851c7d1738c295f2f1e408a41113e59e0a699b19.png) ![擷取](https://europe1.discourse-cdn.com/flex013/uploads/rasa/original/3X/0/b/0beeb9308546720ff91a6b1fb1302323a9a0d5cb.png)

My csv data looks like this

![csv](https://europe1.discourse-cdn.com/flex013/uploads/rasa/original/3X/4/a/4a226848bc27c835e746179b0d649caf231a7212.png)

domain

![image](https://europe1.discourse-cdn.com/flex013/uploads/rasa/original/3X/2/6/262236cbdf0d284d604d587623a40b650dcb5ae5.png)

Where do I need to add anything (ex. nlu or stories)

---

<div class="post-metadata">

**Author:** ![nik202](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/nik202/32/16098_2.png) [@nik202](https://forum.rasa.com/u/nik202)\
**Post date:** [November 23, 2021, 1:27pm UTC](https://forum.rasa.com/t/how-to-make-rasa-chatbot-fetching-csv-file/49250/20 "2021-11-23T13:27:21Z")

</div>

@dan246 send me your action.py file, your .csv file.

[Next page](https://forum.rasa.com/t/how-to-make-rasa-chatbot-fetching-csv-file/49250.md?page=2)
