Skip to content

Make Stefan Excel parser a bit more concise #2

Description

@terrycojones

Hi Stefan. You could use a dict to hold the conversion values for your Excel. It's less code and it's faster. E.g.:

#!/usr/bin/env python

# You'll need to pip import openpyxl
import openpyxl

excelFile = openpyxl.load_workbook('stefan-data.xlsx')
sheet1 = excelFile.active

convert = {
    0: '<10',
    0.5: 10,
    1: 20,
    1.5: 30,
    2: 40,
    2.5: 60,
    3: 80,
    3.5: 120,
    4: 160,
    4.5: 240,
    5: 320,
    5.5: 480,
    6: 640,
    6.5: 960,
    7: 1280,
    7.5: 1920,
    8.5: 2560,
}

for row in sheet1.iter_rows():
    for cell in row:
        if cell.value in convert:
            cell.value = convert[cell.value]

excelFile.save('stefan-new-data.xlsx')

And there's no value for 8?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions