Origin Ver. and Service Release (Select Help-->About Origin):
Operating System: Windows
Data file:https://my.originlab.com/ftp/forum_and_kbase/Images/Rheology.xlsx
Hi, I'm trying to import some data (see attached) using something similar to what has been supplied in the Python for Origin video tutorial (https://www.youtube.com/watch?v=HVW-WThxzHk&list=PLAH66v11YrfD-_q9QaA-lnjCDdlzk1dHu&index=3&t=1581s&ab_channel=OriginLabCorp.).
I've pretty much just copied and pasted the script from the video and removed the code to process the first four lines (in the video script) and just used the rest of the script to import the rest of the data but it doesn't work? Is it due to my data having more than one column?
I am using the top line as my long name and the second line as the units. The rest of the code is to fill in the data sheet.
import originpro as op
import pandas as pd
import os
def read_file(file):
wks = op.find_sheet() # Get the active worksheet.
with open(file, 'r') as f:
# Read the Longname line
line = f.readline()
cols = line.split()
# Read the Unit line
line = f.readline()
wks.set_labels([line], 'U')
# Read in the data
rows = []
for line in f.readlines():
rows.append(line.split())
df = pd.DataFrame(data=rows, columns=cols)
# Save data to worksheet
wks.from_df(df)
# Set column designation
wks.cols_axis('XY')
# Set sheet name to file name
wks.name = os.path.basename(file)
# The file chosen by Origin import filter is placed into the fname$
# LabTalk variable. Must bring it into Python.
fname = op.get_lt_str('fname')
data = read_file(fname)
Thanks in advance,
Jason