Questions about data output in Python and Excel

33 views Asked by At

For Excel use, I want to create a code that represents A1, A2,...D1, ... AB1, AB2, ...

field = [A, B, C, ..., AA, AB, ..., YZ, ZZ]
data = [[1, 2,3,4,5], [2, 3,4,5,6], [3, 5,4,3,5], [4, 5,6,7,7],...] #[index, data1, data2,...]

for i in field:                # A, B, C, ...
    for j in range(0,10):      # First index in data
        for k in range(1,4):
            print(str(i)+data[j][k])

The result I want is A2 A3 A4 A5 B3 B4 B5 B6 C5 C4 C3 C5 ...

I think I need to use a break statement, but how do I do that?

1

There are 1 answers

3
SimonGPT On
for i, column in enumerate(field):  # A, B, C, ...
    for j in range(len(data)):      # Iterate over rows in data
        if j < 10:  # Limit to first 10 rows if necessary
            for k in range(1, 5):   # Assuming you want to skip the first element in each row and limit to next 4
                if i < len(data[j]) - 1:  # Check if column exists in this row
                    print(f"{column}{j+2}: {data[j][k]}")
                else:
                    break  # Break if the column index exceeds the data row length