Skip to main content
Question

Splitting attributes to Excel

  • June 15, 2016
  • 2 replies
  • 50 views

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!

This post is closed to further activity.
It may be an old question, an answered question, an implemented idea, or a notification-only post.
Please check post dates before relying on any information in a question or answer.
For follow-up or related questions, please post a new question or idea.
If there is a genuine update to be made, please contact us and request that the post is reopened.

2 replies

takashi
Celebrity
  • 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

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!