Search code examples
pythonlistappendopenpyxlincrement

How to add increment numbers to a new column? Using only openpyxl or without Pandas


As this challenge is for me to not use pandas to achieve this result. I have tried many variations and have failed. What can I do? I am suppose to make a customer id that keeps going up as I go down the column starting with the number 320 in excel.

[‘A’]=“customer id”
id=[‘A:A50’]

For row in id:
For cell in row: 
    Cell.value=cell.value.append(i in range(320,370)

Solution

  • Take look at enumerate built-in function, consider following simple example

    letters = ['A','B','C','D','E']
    for inx, letter in enumerate(letters, 101):
        print(inx, letter)
    

    gives output

    101 A
    102 B
    103 C
    104 D
    105 E
    

    Second optional argument is start, 101 in example above, assumed 0 if not given.