-4

[code_image....

it should print similar output in one col ]1>

from fuzzywuzzy import fuzz
from fuzzywuzzy import process
query = "Apple"
#set of DATA 25 records
choices = ["apil",
    "apple",
    "Apille",
    "aple",
    "apil",
    "appple",
    "Apple APPLE",
    "Apil Orange",
    "apples"
]
process.extract(query, choices)
#### Printing Accuracy Value
print ("List of ratios: ")
print (process.extract(query, choices), "\n")
#process.extractone(query, choices)
print ("\nBest among the above list ----->",process.extractOne(query, choices))

Output:

List of ratios:

[('apple', 100), ('appple', 91), ('apples', 91), ('Apple APPLE', 90), ('aple', 89)]

Best among the above list -----> ('apple', 100)

Jiri Janous
  • 1,189
  • 1
  • 6
  • 14
Assassin
  • 72
  • 9
  • 2
    Hi Assassin, welcome to StackOverflow! Could you show us, what you've tried so far? Also you might consider reading [this](https://stackoverflow.com/help/asking) about how to ask questions. Following those guidelines will almost certainly increase your chance of getting answers. – jofrev Sep 18 '19 at 10:32
  • pyspark or python program to match similar kinds of word and it should be display in table format like.. similar word different spelling like apple to aaple . these words should be viewed in table format – Assassin Sep 18 '19 at 10:40
  • Have you written any code on your own so far? If so please share it with us and I'm sure you will be helped. If not, don't just expect the community to do your homework for you, since that is not what StackOverflow is there for. You should show some effort of your own first! – jofrev Sep 18 '19 at 11:00
  • I've uploaded an image that contains my code..i just need to display the answer in table format ..... – Assassin Sep 18 '19 at 11:38
  • Thanks @ jofrev It worked ..... – Assassin Sep 19 '19 at 04:38

1 Answers1

0

I only had to change one line of and add another one to your snippet. You can find comments where I applied those changes, which explain what they do. I wasn't sure about the exact output format you wanted, so feel free to ask again if it's not what you wanted.

Take a look at list comprehension if you want to dig deeper into how the last line works.

from fuzzywuzzy import fuzz
from fuzzywuzzy import process
query = "Apple"
#set of DATA 25 records
choices = ["apil",
    "apple",
    "Apille",
    "aple",
    "apil",
    "appple",
    "Apple APPLE",
    "Apil Orange",
    "apples"
]
# 1st change here
# The next line stores tuples of each choice and it's according similarity measure in a list. This entries seem to be ordered from what your snippet shows.
ordered_choices = process.extract(query, choices)
#### Printing Accuracy Value
print ("List of ratios: ")
print (process.extract(query, choices), "\n")
#process.extractone(query, choices)
print ("\nBest among the above list ----->",process.extractOne(query, choices))

# 2nd change here
# The following line takes the first element of each tuple in the list and adds is to another list, which is afterwards printed. 
print("\nOrdered choices: ", [choice for choice, value in ordered_choices])

jofrev
  • 324
  • 3
  • 11