Created
May 18, 2020 07:10
-
-
Save mithunkamat/27a80ca5a276b10b39780e4225bec6af to your computer and use it in GitHub Desktop.
Example code iteratively building a 'mappings' dictionary from a table in Excel using openpyxl. On seeing two blank lines, we assume the table has ended.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
empty = 0 # initialize our empty cell count | |
while empty < 2: | |
# increment the row number (which begins at the row we found 'Internal' | |
row += 1 | |
# assign the value we find in the 'Internal' column to internal | |
internal = ws[f'B{row}'].value | |
if internal is None: | |
empty += 1 # if we get blank row, increment empty counter | |
else: | |
# otherwise we have a mapping to add to the mappings dict | |
mappings[internal] = ws[f'D{row}'].value | |
empty = 0 # also re-initialize the empty counter |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment