Question

Splitting attributes to Excel


Badge

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

Userlevel 2
Badge +17

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)
Badge

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! 

Reply