I want a import some columns from an excel spreadsheet, however, I also want to run some lines of code on each column. So i need it to read a specific column, run some lines of code and then return to pick another column and do the same thing. I'm guessing this will work with an iterative loop but I'm new to pyhton so I can't seem to get the syntax right. For now this is what I have which is very manual:
import openpyxl
import numpy as np
book = openpyxl.load_workbook('new.xlsx')
sheet = book.active
nx = 19
ny = 19
rangedata = []
for c in sheet.iter_cols(4,4,2,362):
columndata = []
for r in c:
columndata.append(r.value)
cd = np.asarray(columndata)
P = np.flip(cd.reshape(nx,ny), axis=0)
rangedata = []
for d in sheet.iter_cols(4,5,2,362):
Column = []
for s in d:
Column.append(s.value)
nd = np.asarray(Column)
Q = np.flip(nd.reshape(nx,ny), axis=0)
I've tried using but it is only returning the last column
rangedata = []
for col_cells in sheet.iter_cols(min_col=4, max_col=8):
for cell in col_cells:
for c in sheet.iter_cols(4,8,2,362):
columndata = []
for r in c:
columndata.append(r.value)
cd = np.asarray(columndata)
P = np.flip(cd.reshape(nx,ny), axis=0)