How to pass arguments from excel column to python user defined function and loop every rows? -




i trying import data excel , loop each dataset. have data in column a, b, c of excel sheet. use openpyxl import data excel workbook. don't know way refer column a,b,c arguments function. please see image:

sample image

and function:

x = 0.2 def quadratic(a, b, c, x):     return a*x**2 + b*x + c 

i want pass data of column a, b, c arguments a, b, c , loop through every row (in image, each row row 2 18).

you can export data in spreadsheet csv, , use python builtin csv module (https://docs.python.org/3/library/csv.html) go through line line.

the following code adapted example in doc should work, did not run it. reads csv line line, casts values floats, , calls function

import csv  x = 0.2 def quadratic(a, b, c, x):     return a*x**2 + b*x + c  open('data.csv', newline='') csvfile:     datareader = csv.reader(csvfile, delimiter=' ', quotechar='|')     row in datareader:         data = map(float,row)         print(quadratic(*data,x)) 




wiki

Comments

Popular posts from this blog

Asterisk AGI Python Script to Dialplan does not work -

python - Read npy file directly from S3 StreamingBody -

kotlin - Out-projected type in generic interface prohibits the use of metod with generic parameter -