Python Forum
Help with to check an Input list data with a data read from an external source
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help with to check an Input list data with a data read from an external source
#1

.py   real_Time_Sinu_V5.py (Size: 7.06 KB / Downloads: 25)

I am not from coding background but currently am coding using python due to job requirements.
I have attached the code with which I need help with. The basics of the code is that I am trying to read and write data from some electronic sensors using some data acquisition systems (DAQ).
These are what I am trying to achieve using this code:
1. Read an external .csv/.txt file containing these following column names (Disp, Voltage 1, Voltage 2, Logic). This is then saved as a data frame.

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.

5. this check will go for the length of the data frame.

6. Once the full check across the data frame is done it is considered a cycle completion.

7. The whole loop needs to run for as long as cycle number <= max number of cycles (which is a user defined input declared previously).

Will be greatly indebted if I can get a solution to this dilemma. As as per my attached code the checking of read displacement with the Disp value in the data frame is not occurring correctly
Reply
#2
As I understand your request:

Quote:1. Read data from an example Excel/csv/text which you did not supply.

2. Returns True or False, so for testing, any list of True or False values would suffice to mimic your daq/Disp comparison. If this list reflects the reality on the ground there, would be better. If we had such a list, even better!

4. If the daq/Disp comparison turns out to be False, write the values from the csv we don't have to the datafame we don't have.

5. Check the whole length of the data frame we don't have.

6. After checking the whole df stop.

7. But don't stop until you have checked the df x cycles where x is a number we don't have.

How then can I try this out to see if it works or not?

Doesn't actually seem to hard, if one had some data to work with and check.
Reply
#3
(Mar-08-2024, 10:30 AM)Pedroski55 Wrote: As I understand your request:

Quote:1. Read data from an example Excel/csv/text which you did not supply.

2. Returns True or False, so for testing, any list of True or False values would suffice to mimic your daq/Disp comparison. If this list reflects the reality on the ground there, would be better. If we had such a list, even better!

4. If the daq/Disp comparison turns out to be False, write the values from the csv we don't have to the datafame we don't have.

5. Check the whole length of the data frame we don't have.

6. After checking the whole df stop.

7. But don't stop until you have checked the df x cycles where x is a number we don't have.

How then can I try this out to see if it works or not?

Doesn't actually seem to hard, if one had some data to work with and check.


.xlsx   Sample Input File.xlsx (Size: 19.03 KB / Downloads: 22)
.csv   sample read displacement.csv (Size: 2.41 KB / Downloads: 14)

My bad I have supplied two attachments one is the input file and the other is the sample displacement being read. The max number of cycles is not fixed but for this purpose we can assume it to be let us say 3. I hope I was able to clarify.
Reply
#4
Maybe something like this is what you are looking for?

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}')
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  PyYAML read list of int zisco 2 323 Apr-02-2024, 12:36 PM
Last Post: zisco
  difference between forms of input a list to function akbarza 6 1,043 Feb-21-2024, 08:02 PM
Last Post: bterwijn
  [solved] list content check paul18fr 6 719 Jan-04-2024, 11:32 AM
Last Post: deanhystad
  manually input data jpatierno 0 346 Nov-10-2023, 02:32 AM
Last Post: jpatierno
  Input network device connection info from data file edroche3rd 6 1,063 Oct-12-2023, 02:18 AM
Last Post: edroche3rd
  How to read module/class from list of strings? popular_dog 1 483 Oct-04-2023, 03:08 PM
Last Post: deanhystad
Question in this code, I input Key_word, it can not find although all data was exact Help me! duchien04x4 3 1,056 Aug-31-2023, 05:36 PM
Last Post: deanhystad
  Correctly read a malformed CSV file data klllmmm 2 1,972 Jan-25-2023, 04:12 PM
Last Post: klllmmm
  user input values into list of lists tauros73 3 1,075 Dec-29-2022, 05:54 PM
Last Post: deanhystad
  Read nested data from JSON - Getting an error marlonbown 5 1,383 Nov-23-2022, 03:51 PM
Last Post: snippsat

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020