Fetching data from csv file

@MuraliChandran14…hello this is exactly what am also looking…my scenario is I have a csv file that contains drug name and its description…so when a user asks for a drug description by providing a drug name then I want the bot to take the drug name and finds the description from csv file then display it to the user…how can we query that??

Hey @faiza_conte

I did a quick method, I hope you can build from this!

import csv

    def excelcheck():
        csvfile = open("Test.csv")
        reader = csv.reader(csvfile)

        # Get from user input drug name:
        drugno = "Liam" 

        for row in reader:
            # Check for the user input
            if drugno in row[0]:
                print(row[0]+"\t"+row[1]);

Sample Output:

@MuraliChandran14 thank you so much

@MuraliChandran14 Here I want to add the else part incase if it is not found in the csv file then to say * sorry not found*…after the if condition I put else and tries like this

  • else: dispatcher.utter_message(template=“utter_notfound”)

But it prints both the if and else part when I make a conversation with the bot…can you correct me …

@faiza_conte you can add break in the If statement once the drug description is found. That’s the reason its printing both if and else statements…

drugno = "Right"
nodescription = False;
for row in reader:
    # Check for the user input
    if drugno in row[0]:
        print(row[0]+"\t"+row[1])
        break;
    else:
       nodescription = True

if nodescription:
    print("No Description Found")

Okay thanks I will try that

@MuraliChandran14 the output become like this…when the drug name is not found it does throws an error message but when the drug name is found it prints both the if and else part as u can see from the picture below

Hello everyone, I’m working on a chatbot project and I want to fetch csv data that inlcudes college names, locations, email_ids, contacts and intakes. Suppose the user asks for the location or contact of particular college then it should get that location from the csv file and bot will give the output as “here is the location/contact details/ email id of ‘clg_name’”. Please help me with this. Thanks

Hi @Shruti ,

Did you find any resource to execute your use case?

Hi, I am working on chatbot project and I want to fetch the data from CSV and excel the include employee name, employee id, employee status, group, department, if suppose the user ask for employee status according to the employee name tell me the employee status or according to group , please help me with this. Thanks

actions.py (2.0 KB)

1 Like

Hi there!

In

location = tracker.get_slot('EmployeeName')

You never use location in the code…

Instead, should’t be:

EmployeeName = tracker.get_slot('EmployeeName')   ?

Pedro Lopes

my question and answer should be like this user : hi bot: Hey how can i help you user: can i know the employee status bot: can you specify the name of the employee user: prakash gouda bot: Active

user: can i know the primary skill of the employee bot: can you specify the name of the employee or employee id user: EOOO198 bot: here is a primary skill of the employee id ; SQL, JAVA , Python

user: can you tell me the secondary skill of the employee bot: can you specify the name of the employee od employee id user: E00034 bot: here is a secondary skill of the employee; machine learning , data science

and I am working with excel data , I need to fech the data like primary skill of the employee , secondary skill of the employee , designation according to Employee Name or ID , from the excel sheet 1 , can you help me with custom action sample

class actionfindgrpepn(Action): def name(self) → Text: return “action_findgrpepn”

def run(self,
        dispatcher: CollectingDispatcher,
        tracker: Tracker,
        domain: Dict[Text, Any]
        ) -> List[Dict[Text, Any]]:
    # get the EmployeeName slot
    EmployeeName = tracker.get_slot('EmployeeName')
    # read the  xlsx file

    df = pd.read_excel(r"C:/Users/ADARSH/Downloads/Chat_Voice_Bot.xlsx",
                       sheet_name="EMP_Skill_Master")

output = df[df[‘Employee Name’]==EmployeeName] output df.loc[0,‘Employee Status’] if output: reply = "\n- " + "\n- ".join([item[df[‘Employee Status’]] for item in output]) # utter the message dispatcher.utter_message(text=str(reply))

else: # the list is empty dispatcher.utter_message(f"Sorry… Could not find ")

PS C:\Users\ADARSH\PycharmProjects\bBott> rasa run actions 2021-11-18 17:16:45 INFO rasa_sdk.endpoint - Starting action endpoint server… 2021-11-18 17:16:48 ERROR rasa_sdk.executor - Failed to register package ‘actions’. Traceback (most recent call last): File “c:\users\adarsh\pycharmprojects\bbott\venv\lib\site-packages\rasa_sdk\executor.py”, line 262, in register_package self._import_submodules(package) File “c:\users\adarsh\pycharmprojects\bbott\venv\lib\site-packages\rasa_sdk\executor.py”, line 225, in _import_submodules self._import_module(full_name) File “c:\users\adarsh\pycharmprojects\bbott\venv\lib\site-packages\rasa_sdk\executor.py”, line 239, in import_module module = importlib.import_module(name) File "C:\Users\ADARSH\anaconda3\lib\importlib_init.py", line 127, in import_module return _bootstrap._gcd_import(name[level:], package, level) File “”, line 1014, in gcd_import File “”, line 991, in find_and_load File “”, line 975, in find_and_load_unlocked File “”, line 671, in load_unlocked File “”, line 783, in exec_module File “”, line 219, in call_with_frames_removed File “C:\Users\ADARSH\PycharmProjects\bBott\actions\actions.py”, line 13, in import nltk File "c:\users\adarsh\pycharmprojects\bbott\venv\lib\site-packages\nltk_init.py", line 153, in from nltk.translate import * File "c:\users\adarsh\pycharmprojects\bbott\venv\lib\site-packages\nltk\translate_init.py", line 24, in from nltk.translate.meteor_score import meteor_score as meteor File “c:\users\adarsh\pycharmprojects\bbott\venv\lib\site-packages\nltk\translate\meteor_score.py”, line 13, in from nltk.corpus import WordNetCorpusReader, wordnet File "c:\users\adarsh\pycharmprojects\bbott\venv\lib\site-packages\nltk\corpus_init.py", line 64, in from nltk.corpus.reader import * File "c:\users\adarsh\pycharmprojects\bbott\venv\lib\site-packages\nltk\corpus\reader_init.py", line 106, in from nltk.corpus.reader.panlex_lite import * File “c:\users\adarsh\pycharmprojects\bbott\venv\lib\site-packages\nltk\corpus\reader\panlex_lite.py”, line 15, in import sqlite3 File "C:\Users\ADARSH\anaconda3\lib\sqlite3_init.py", line 23, in from sqlite3.dbapi2 import * File “C:\Users\ADARSH\anaconda3\lib\sqlite3\dbapi2.py”, line 27, in from _sqlite3 import * ImportError: DLL load failed while importing _sqlite3: The specified module could not be found.

Hi , i am getting this error , i install nltk, but not able to connect to https server , i run the actions file can you help me with this error

what you mean by this, or are you not able to connect with SQL database? can you elaborate more and please format the above error or share the screenshot.

i am working on chatbot fetching the data from the xlsx sheet, all the files are working fine previously and I am able to connect to https server as well,

after that, I created another rasa project in 3.8 virtual env , due to some dependency error i downloaded the keras =2.6.0 and trained that bot it is working fine in rasa shell

but not able to connect to https server, to start conversion with bot in HTTP widget -in actions.py file I downloaded the nltk ,nltk.download(“puntk”)

i am unable to connect https server, I run the actions.py file, and I want deploy in HTTP widgets , but not able to connect to server , in rasa shell it’s working fine all the questions which I bot is giving output,

@AdarshTugao what is your front end ADARSH? and when you say HTTP widgets or HTTPs what exactly you means, are you bot in running on server or local machine?

running a bot on server on localhost = “http://localhost:5005

action endpoint server 5055 and local server on 5005