Skip to main content
Solved

Value mapping but by number of items

  • August 14, 2018
  • 1 reply
  • 8 views

Forum|alt.badge.img

Hi,

Bit of on odd one i cannot work out. I have some tabular data e.g.

203040325

The headers are 20,30,40 with values 3,2,5.

Is there a simple oway to end up with

20304020,20,2030,3040,40,40,40,40

Thanks

Best answer by david_r

Try the following in a PythonCaller:

import fmeobjects

def multiply(feature):
    attr_names = feature.getAllAttributeNames()
    for attr in attr_names:
        if attr.isdigit():
            value = int(feature.getAttribute(attr))
            result = ','.join([attr] * value)
            feature.setAttribute(attr, result)
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.

1 reply

david_r
Celebrity
  • 8394 replies
  • Best Answer
  • August 14, 2018

Try the following in a PythonCaller:

import fmeobjects

def multiply(feature):
    attr_names = feature.getAllAttributeNames()
    for attr in attr_names:
        if attr.isdigit():
            value = int(feature.getAttribute(attr))
            result = ','.join([attr] * value)
            feature.setAttribute(attr, result)