Skip to main content
Question

Splitting attributes to Excel


Forum|alt.badge.img

Hi,

I am trying to split attribute as below. Input file is in MITAB. The number of fruit items for each is variable so I don't think I can use AttributeSplitter. I have also tried with PythonCaller with feature.getAttribute('B').split('|') and the feature.setAttribute but it would only give me the last fruit (ie, orange, apple, and pear) out in Excel. I can't figure out why or solve the problem. Is there any suggestions? Thanks!

2 replies

takashi
Evangelist
  • June 15, 2016

Hi @judychang, I think you can use the combination of the AttributeSplitter and ListExploder.

0684Q00000ArKNKQA3.png

Of course you can use the PythonCaller too. e.g.

# PythonCaller Script Example
class FeatureProcessor(object):
    def input(self, feature):
        fruits = feature.getAttribute('B')
        if fruits:
            for item in fruits.split('|'):
                feature.setAttribute('B', item)
                self.pyoutput(feature)
        else# 'B' is empty.
            self.pyoutput(feature)

Forum|alt.badge.img
  • Author
  • June 15, 2016
takashi wrote:

Hi @judychang, I think you can use the combination of the AttributeSplitter and ListExploder.

0684Q00000ArKNKQA3.png

Of course you can use the PythonCaller too. e.g.

# PythonCaller Script Example
class FeatureProcessor(object):
    def input(self, feature):
        fruits = feature.getAttribute('B')
        if fruits:
            for item in fruits.split('|'):
                feature.setAttribute('B', item)
                self.pyoutput(feature)
        else# 'B' is empty.
            self.pyoutput(feature)

Thanks! The transformers work! 


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings