Transferring user entered data from an Excel worksheet to a Python Script -
Transferring user entered data from an Excel worksheet to a Python Script -
i'm writing script , able interact ms excel. 1 time run script, open excel worksheet, have user come in data, basic calcs in excel, , homecoming calculated info , of user entered info script.
i'm doing because i'd allow user come in info @ 1 time , not have reply prompt after prompt , because i'm new python , not close beingness able write gui.
here's illustration of i'm trying do:
table 1 (range1 in excel worksheet):
user enters fraction , xa:aa info , excel calculates blend. blend info on xa:aa returned python script used in script farther calculations. info entry table longer (more rows of info entry) showing plenty of subset give sense i'm trying do:
stream 1 2 3 4 5 blend fraction 10% 60% 20% 10 100% xa 100 150 175 57 135.0 yg 30.7 22 18 12.2 25.6 aa 210 425 375 307 352.2
table 2 (range2 in same excel worksheet)
user enters info , returned script farther calculations:
min max incr temp 45 60 5 press 7.2 7.8 0.2 cf 1 5 1
once info entered excel , transferred script, finish script.
how go doing ? excel seems easiest way set table entry info if there way, please allow me know. if excel, how go doing ?
here's potential approach using pandas. if input file doesn't exist, writes dummy file (modify suit), opens excel file, , reads dataframe 1 time user has closed. replace excel_path
path excel install (i'm using libreoffice here).
import os import subprocess import pandas pd input_file = 'input.xlsx' excel_path = 'soffice' ############# # setup stuff ############# if not os.path.isfile(input_file): input_template = pd.dataframe(columns=['1','2','3','4']) # additional code set space user input values input_template.to_excel(input_file) else: # phone call excel , open input file subprocess.call([excel_path, input_file]) # read modified input dataframe excel_input = pd.read_excel(input_file) ################ # body of script ################
python excel pandas
Comments
Post a Comment