PythonDataScienceHandbook icon indicating copy to clipboard operation
PythonDataScienceHandbook copied to clipboard

Help Needed: Extract Data from Image to Excel Format

Open muhammedsalahudheen16-hub opened this issue 1 year ago • 6 comments

Help Needed: Extract Data from Image to Excel Format

Description

I have an image containing tabular data with various fields such as sales dates, customer names, dealer names, amounts, phone numbers, and more. I need help extracting this data accurately and populating it into a structured Excel file.

Requirements

Extract all data entries from the provided image.

Use a fixed Form Number (e.g., 12428_000001) for all records on the same page.

Increment Record Numbers starting from 1 for each entry.

Format the Sales Date as MM/DD/YYYY.

Convert Basic Amount values from millions to full numbers (multiply by 1,000).

Calculate Net Amount as the sum of Basic Amount and Insurance Amount.

Fill all other fields exactly as shown in the image.

Maintain data accuracy and formatting.

Column Structure for Excel

FORM NO.

RECORD NO.

SALES DATE

CUSTOMER NAME

INITIALS

E-MAIL ADDRESS

DEALER NAME

CUSTOMER ADDRESS

CITY

STATE

CUSTOMER PHONE

DEALER PHONE

DELIVERY TIME

INVOICE NO.

INSURANCE POLICY NO.

CHESIS NO.

BASIC AMOUNT

INSURANCE AMOUNT

TOTAL AMOUNT (if applicable)

DISCOUNT

NET AMOUNT

Files Provided

Image file containing raw data.

Blank Excel template to fill in.

Additional Notes

Page or form changes should have unique Form Numbers to distinguish data.

Assistance requested for manual extraction or automated process suggestions.

Suggested Solution: Automating Image → Excel Extraction

This can be solved by building a small OCR + data processing pipeline in Python. Below is a practical approach you can use.

Approach

  1. Extract text from the image (OCR)

    Use pytesseract or easyocr

  2. Parse the extracted text

    Split into rows based on line breaks Identify fields using consistent patterns in the data

  3. Apply required transformations

    Use fixed FORM NO. (e.g., 12428_000001) Increment RECORD NO. starting from 1 Convert SALES DATE → MM/DD/YYYY Multiply BASIC AMOUNT by 1000 Compute NET AMOUNT = BASIC AMOUNT + INSURANCE AMOUNT

  4. Export to Excel

    Use pandas with openpyxl or xlsxwriter


Example Code

import pytesseract import cv2 import pandas as pd from datetime import datetime

image = cv2.imread("input.jpg") text = pytesseract.image_to_string(image) lines = [line.strip() for line in text.split("\n") if line.strip()] records = [] form_no = "12428_000001" record_no = 1

for line in lines: try: parts = line.split() sales_date = datetime.strptime(parts[0], "%d-%m-%Y").strftime("%m/%d/%Y") customer_name = parts[1]

    basic_amount = float(parts[-2]) * 1000
    insurance_amount = float(parts[-1])
    net_amount = basic_amount + insurance_amount

    records.append({
        "FORM NO.": form_no,
        "RECORD NO.": record_no,
        "SALES DATE": sales_date,
        "CUSTOMER NAME": customer_name,
        "BASIC AMOUNT": basic_amount,
        "INSURANCE AMOUNT": insurance_amount,
        "NET AMOUNT": net_amount
    })

    record_no += 1
except:
    continue

df = pd.DataFrame(records) df.to_excel("output.xlsx", index=False)

enzo33three avatar May 02 '26 10:05 enzo33three

For the OCR step, ensure you have the correct Tesseract version installed that matches your pytesseract version, as incompatibilities could lead to inaccurate text extraction from your image.

fJpmjZdgpD avatar Jul 17 '26 12:07 fJpmjZdgpD

Thanks for the suggestion.

I'll verify that the installed Tesseract version matches the pytesseract version. That could definitely explain inconsistent OCR results.

On Fri, Jul 17, 2026 at 2:11 PM Ethan Carter @.***> wrote:

fJpmjZdgpD left a comment (jakevdp/PythonDataScienceHandbook#435) https://github.com/jakevdp/PythonDataScienceHandbook/issues/435#issuecomment-5003125967

For the OCR step, ensure you have the correct Tesseract version installed that matches your pytesseract version, as incompatibilities could lead to inaccurate text extraction from your image.

— Reply to this email directly, view it on GitHub https://github.com/jakevdp/PythonDataScienceHandbook/issues/435?email_source=notifications&email_token=CI5ETWYGZXXYHJ3Q3EA35BL5FIJWNA5CNFSNUABFM5UWIORPF5TWS5BNNB2WEL2JONZXKZKDN5WW2ZLOOQXTKMBQGMYTENJZGY32M4TFMFZW63VKON2WE43DOJUWEZLEUVSXMZLOOSWGM33PORSXEX3DNRUWG2Y#issuecomment-5003125967, or unsubscribe https://github.com/notifications/unsubscribe-auth/CI5ETW54LXIG4U7ZOUNTIJT5FIJWNAVCNFSNUABEKJSXA33TNF2G64TZHM3DKMZYHA4TCNZ3JFZXG5LFHMZTGNRYHA2DAMJRGKQXMAQ . Triage notifications, keep track of coding agent tasks and review pull requests on the go with GitHub Mobile for iOS https://github.com/notifications/mobile/ios/CI5ETWZS3FQMQRU5WG2UPTD5FIJWNA5CNFSNUABFM5UWIORPF5TWS5BNNB2WEL2JONZXKZKDN5WW2ZLOOQXTKMBQGMYTENJZGY32M4TFMFZW63VKON2WE43DOJUWEZLEUVSXMZLOOSVGM33PORSXEX3JN5ZQ and Android https://github.com/notifications/mobile/android/CI5ETW5ZUIE3RU5P4E3HWZ35FIJWNA5CNFSNUABFM5UWIORPF5TWS5BNNB2WEL2JONZXKZKDN5WW2ZLOOQXTKMBQGMYTENJZGY32M4TFMFZW63VKON2WE43DOJUWEZLEUVSXMZLOOSXGM33PORSXEX3BNZSHE33JMQ. Download it today! You are receiving this because you are subscribed to this thread.Message ID: @.***>

bsoua8745s12 avatar Aug 03 '26 14:08 bsoua8745s12

Consider using pandas to efficiently organize the extracted data into the Excel template after you've processed it with pytesseract. This could simplify the calculation of the Net Amount and ensure that all fields are filled systematically according to your specified column structure.

jacewq avatar Aug 16 '26 20:08 jacewq

Since you have a structured blank Excel template, using pandas to write the final dataframe might overwrite the template's

christianfrei791 avatar Sep 13 '26 14:09 christianfrei791

Thank you for the information. I’ve received it and will review it shortly.

On Sun, Sep 13, 2026 at 3:08 PM Christian Frei @.***> wrote:

christianfrei791 left a comment (jakevdp/PythonDataScienceHandbook#435) https://github.com/jakevdp/PythonDataScienceHandbook/issues/435#issuecomment-5653773435

Since you have a structured blank Excel template, using pandas to write the final dataframe might overwrite the template's

— Reply to this email directly, view it on GitHub https://github.com/jakevdp/PythonDataScienceHandbook/issues/435?email_source=notifications&email_token=CKTITMA7GQSRTEGP6KHBV535O2S7BA5CNFSNUABFM5UWIORPF5TWS5BNNB2WEL2JONZXKZKDN5WW2ZLOOQXTKNRVGM3TOMZUGM22M4TFMFZW63VKON2WE43DOJUWEZLEUVSXMZLOOSWGM33PORSXEX3DNRUWG2Y#issuecomment-5653773435, or unsubscribe https://github.com/notifications/unsubscribe-auth/CKTITMAY5R4VDBTUTEG76335O2S7BAVCNFSNUABEKJSXA33TNF2G64TZHM3DKMZYHA4TCNZ3JFZXG5LFHMZTGNRYHA2DAMJRGKQXMAQ . Triage notifications, keep track of coding agent tasks and review pull requests on the go with GitHub Mobile for iOS https://github.com/notifications/mobile/ios/CKTITMBR4W3JQKPLCIWUMPL5O2S7BA5CNFSNUABFM5UWIORPF5TWS5BNNB2WEL2JONZXKZKDN5WW2ZLOOQXTKNRVGM3TOMZUGM22M4TFMFZW63VKON2WE43DOJUWEZLEUVSXMZLOOSVGM33PORSXEX3JN5ZQ and Android https://github.com/notifications/mobile/android/CKTITMHQFVGH6XMM45XMD3L5O2S7BA5CNFSNUABFM5UWIORPF5TWS5BNNB2WEL2JONZXKZKDN5WW2ZLOOQXTKNRVGM3TOMZUGM22M4TFMFZW63VKON2WE43DOJUWEZLEUVSXMZLOOSXGM33PORSXEX3BNZSHE33JMQ. Download it today! You are receiving this because you are subscribed to this thread.Message ID: @.***>

wafir645fcqs49 avatar Sep 16 '26 15:09 wafir645fcqs49