How to create a automatic discounted price list from Easyocr result?

50 Views Asked by At

So we are tasked to create a code where the result of the Easyocr into a table (specifically food menus). The brick wall starts right after obtaining the result from easyocr since it I tried sorting the result but it sorts per character and number instead of words and price. I know that creating a list manually will solve it but it beats the purpose of automating the code of applying discount on a ocr.

We read the text:

result2 = reader.readtext(IMAGE_PATH, detail=0, slope_ths= 0.2)

result2 contains the following:

['SIZZLING SPECIALS',
 'Spareribs',
 '195.00',
 'Pork Katsudon',
 '175.00',
 'Sizzling Sisig',
 '180.00',
 'Sisig Pulutan',
 '160.00',
 'Pork',
 'Barbeque',
 '160.00',
 'Pork Teriyaki',
 '160.00',
 'Peruvian Chicken',
 '160.,00',
 'Stuffed Squid',
 '345.00',
 'Boneless Bangus',
 '150.00',
 "Tokwa't Baboy",
 '150.00',
 'Sizzling Lomi',
 '110.00']

I wanted to have a result where in the food name and the price are in separate columns. As well as to apply discount to the price.

Column 1 Column 2
Spareribs 195.00-20%
Pork Katsudon 175.00-20%
... ...
... ...
... ...
Sizzling lomi 115.00-20%
1

There are 1 best solutions below

0
On

You would need to do some data cleaning, but try the following:

import pandas as pd

result2 = ['SIZZLING SPECIALS',
           'Spareribs',
           '195.00',
           'Pork Katsudon',
           '175.00',
           'Sizzling Sisig',
           '180.00',
           'Sisig Pulutan',
           '160.00',
           'Pork',
           'Barbeque',
           '160.00',
           'Pork Teriyaki',
           '160.00',
           'Peruvian Chicken',
           '160.,00',
           'Stuffed Squid',
           '345.00',
           'Boneless Bangus',
           '150.00',
           "Tokwa't Baboy",
           '150.00',
           'Sizzling Lomi',
           '110.00']

# Remove SIZZING SPECIALS and Pork
result2 = result2[1::]
del result2[result2.index("Pork")]

result_final = pd.DataFrame([
    {"Column 1": result2[2*i],
     "Column 2": result2[2*i+1]} for i in range(len(result2) // 2)])

result_final
Column 1 Column 2
Spareribs 195.00
Pork Katsudon 175.00
Sizzling Sisig 180.00
Sisig Pulutan 160.00
Barbeque 160.00
Pork Teriyaki 160.00
Peruvian Chicken 160.,00
Stuffed Squid 345.00
Boneless Bangus 150.00
Tokwa't Baboy 150.00
Sizzling Lomi 110.00