The Origin Forum
File Exchange
Try Origin for Free
The Origin Forum
Home | Profile | Register | Active Topics | Members | Search | FAQ | Send File to Tech support
Username:
Password:
Save Password
Forgot your Password? | Admin Options

 All Forums
 Origin Forum for Programming
 Forum for Python
 data merge
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

ulhong84

11 Posts

Posted - 05/09/2023 :  8:40:26 PM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Origin Ver. and Service Release (Select Help-->About Origin):
Operating System:OriginPro 2002 (9.9.0220)

I have 10 individual data and import the data one by one as shown below.
How can I import 10 individual data into one table at once?

And what is the commend to disconnet the sheet?


import originpro as op

f = op.path('e')+r'Samples\python\price.dat'
wks = op.new_sheet()

#Use CSV connector which is the default
#and connector will be removes after import
dc = op.Connector(wks)

#Specify the rows to import
ss = dc.settings()
partial = ss['partial']
partial[op.attrib_key('Use')]='1'
partial['col'] = '2','3'

#import from col 2 to col 3
dc.imp(f)


Thank you~




cpyang

USA
1406 Posts

Posted - 05/09/2023 :  9:12:13 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Sorry, we didnt think of adding that to dc class, but you can use the following to remove it


wks.get_book().method_int('dc.remove')


CP
Go to Top of Page

ulhong84

11 Posts

Posted - 05/11/2023 :  8:11:10 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
quote:
Originally posted by cpyang

Sorry, we didnt think of adding that to dc class, but you can use the following to remove it


wks.get_book().method_int('dc.remove')


CP



The code you let know does not have any equal symbol.
Could you check it?


I have another question.
If there is no way to import separate dat into one book,is there other way such as below?
When I have 10 book separately, how can I merge these individual data in to one book? The data format in each book is the same format.

Edited by - ulhong84 on 05/11/2023 10:05:05 PM
Go to Top of Page

minimax

348 Posts

Posted - 05/12/2023 :  03:21:53 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
quote:
The code you let know does not have any equal symbol.


method_int() is mainly used to execute Origin's LabTalk object methods, and it does not require equal sign.

Here its return value is not very helpful, so it is fine not to have equal symbol.

quote:
If there is no way to import separate dat into one book, is there other way such as below?


I suppose there is no python interface to do this yet. (we will check if we could support it later: ORG-27049)

For now you may have to call some LabTalk scripts, like X-Function wAppend:
https://www.originlab.com/doc/X-Function/ref/wAppend

Following is a sample script to merge the imported columns.

import os
import originpro as op

# collect files to be imported
path = os.path.join(op.path('e'), r'Samples\Batch Processing')
csv_files = [os.path.join(path, f) for f in os.listdir(path) if f.endswith('.csv')]

ranges = []
for csvf in csv_files:
    wks = op.new_sheet()
    dc = op.Connector(wks)
    ss = dc.settings()
    partial = ss['partial']
    partial[op.attrib_key('Use')]='1'
    partial['col'] = '2'
    dc.imp(csvf)
    wks.get_book().method_int('dc.remove')
    ranges.append(wks.lt_range())
    
allsheets = '(' + ','.join(ranges) + ')'
op.lt_exec(f'wAppend -r 0 irng:={allsheets} method:=column ow:=[<new>]<new>;')


Go to Top of Page

minimax

348 Posts

Posted - 10/24/2023 :  02:11:05 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi,

Besides calling method_int(), you can also use either of the following ways to remove the connector:

wks = op.new_sheet()
dc = op.Connector(wks,keep_DC=False)

or
dc.imp(csvf)
wks.remove_DC()
Go to Top of Page
  Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000