LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Python and Excel

I try to read an Excel file (.xlsx) and return an 2D Array of string to Labview. 

 

To verify if I am able to correctly read the file:  I read the file and write a CSV file from the original Excel file - this part works even if I have an error (Python returned the following error: <class 'SystemError'> ..\Objects\listobject.c:189: bad argument to internal function).

Python 1.JPG

 

The script is:

 

import pandas as pd

def MyFunction_Excel(path1, path2):
    dfs = pd.read_excel(path1)
    dfs.to_csv(path2)
    return dfs

 

 

I am not able to return the 2D Array.  What I am doing wrong?

 

JM

 

Message 1 of 7
(4,001 Views)

What exactly is the Python script doing besides reading the Excel file? Why not read the file directly in LabVIEW and process it there?



Mark Yedinak
Certified LabVIEW Architect
LabVIEW Champion

"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot
0 Kudos
Message 2 of 7
(3,983 Views)

I actually utilize the report generation toolkit to read this type of file, but it is slow.  I hope to accelarate the process with python.

 

JM

 

 

Python2.JPG

0 Kudos
Message 3 of 7
(3,975 Views)

What format is the file saved in? Is it an Excel file or is it stored as a CSV file? Reading a CSV file is quite fast. If it is in an Excel format, I'm not sure Python will be much faster.



Mark Yedinak
Certified LabVIEW Architect
LabVIEW Champion

"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot
0 Kudos
Message 4 of 7
(3,972 Views)

It is Excel file (*.xlsx).

 

JM

0 Kudos
Message 5 of 7
(3,970 Views)

I recommend that you attach a sample Excel file that is "slow to read".  If it is a very large Excel file, Excel, itself, might be slow to read it.  It might be "complex", i.e. have many Worksheets, be full of Images, Graphs, and other features, and there may be suggestions for "pre-processing" (such as reading the whole file and "exporting" selected Worksheets).

 

Bob Schor

0 Kudos
Message 6 of 7
(3,881 Views)

As for returning the 2D array you might need to 'reserve' array memory be initializing the array before sending it to Python.

/Y

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 7 of 7
(3,875 Views)