I'm relatively new to programming and while doing my university assignment, I've been running into problems with the process.extract()
function from the fuzzywuzzy
package.
The documentation says the function should return a list, however, my code returns an object with a class type of None
.
If I print the process.extract(limit=1)
it returns what looks like a list:
[("Matching string","Fuzz Ratio", "Index")]
However I can't slice this object using []
because it is classified as None
.
I need to be able to get the index of the matching string so either I need to find out why process.extract()
isn't returning a list or how to get the last element out of the None
object.
Thanks and if any clarification is required, let me know.
EDIT: Ok my bad guys I'll try to be more specific.
Minimal reproducable sample:
Note: CSV file is simply two columns of questions and answers, it's from my university so I'm not sure if I'm allowed to upload the exact file, sorry about this.
Ok so weirdly, recreating the example fixed it but I can't tell what is happening still.
The first example is taken from my original code:
import pandas as pd
from fuzzywuzzy import fuzz
from fuzzywuzzy import process
df_chat_bot = pd.read_csv("ChatBot-short.csv")
str_user_question = input("Question: ")
test_var = print(process.extract(str_user_question, df_chat_bot["Question"], limit = 1))
print(type(test_var))
Output of the print(type(test_var)) line is (direct from terminal) "<class 'NoneType'>".
Then, when I went to make the reproduceable bit of code:
from fuzzywuzzy import process
from fuzzywuzzy import fuzz
import pandas as pd
test_user_question = "vsc"
df_chat_bot = pd.read_csv("ChatBot-short.csv")
temp_var = process.extract(test_user_question,df_chat_bot["Question"], limit = 1)
print(temp_var)
print(type(temp_var))
printing this type results in "<class 'List'>"
So what's going on here? Note that I commented out all other code from my original file so the code I pasted here is the only code being run.