Mar-09-2024, 12:33 PM
Maybe something like this is what you are looking for?
Your Excel file is much longer than the csv!
Your Excel file is much longer than the csv!
import pandas as pd import csv # open the XL file xl_file = '/home/pedro/myPython/pandas/xl_files/Sample_ Input_ File.xlsx' dfXL = pd.read_excel(xl_file) # 402 rows # columns = list(dfXL) # ['Disp', 'Voltage 1', 'Voltage 2', 'Logic'] # open the csv csv_file = '/home/pedro/myPython/pandas/csv_files/sample _read_ displacement.csv' dfcsv = pd.read_csv(csv_file) # 190 rows 1 column called Displacement """ 2. A displacement value is then read from a daq and is then checked against the Disp value in the data frame. The comparison is based on the Logic column which is either <= or >=. The check will occur row by row for the input data frame. 3. please keep in mind that once a line/row is checked in the data frame it should not be checked again. 4. when the logical check returns false the Voltage values (Voltage 1 and Voltage 2) are returned as outputs. i.e if my read displacement is checked at the ith line that it is not <= the Disp value in the ith line then my output will be Voltage 1 and Voltage 2 from (i-1)th line.. """ def getVoltsLess(n): if dfcsv['Displacement'][n] <= dfXL['Disp'][n]: # True print(f'Measured voltage {dfcsv["Displacement"][num]} <= required volts {df["Disp"][num]}') return (0, dfcsv['Displacement'][n]) else: # False print(f'Measured voltage {dfcsv["Displacement"][num]} > required volts {df["Disp"][num]}') return (dfXL['Voltage 1'][n], dfXL['Voltage 2'][n]) def getVoltsMore(n): if dfcsv['Displacement'][n] >= dfXL['Disp'][n]: # True print(f'Measured voltage {dfcsv["Displacement"][num]} > required volts {dfXL["Disp"][num]}') return (0, dfcsv['Displacement'][n]) else: # False print(f'Measured voltage {dfcsv["Displacement"][num]} < required volts {dfXL["Disp"][num]}') return (dfXL['Voltage 1'][n], dfXL['Voltage 2'][n]) # just repeat this loop in a loop to do it all again 3 times for num in dfcsv.index: if dfXL['Logic'][num] == '<=': volts = getVoltsLess(num) print(f'Logic is {logic}, volts are {volts}') elif dfXL['Logic'][num] == '>=': volts = getVoltsMore(num) print(f'Logic is {logic}, volts are {volts}')