[PYTHON] IQ Bot Custom Logic: Split Application (Apply to Table, Include Error Control)

The basics of Split handled by IQ Bot are described in this article.

The above only touches on splits for fields, and the logic does not incorporate error control etc., so I will introduce it a little further here.

Logic to apply Split to a table

For example, if it is a field, what happens if you apply the logic that defines field_value = field_value.split ("bank ") [0] to the field?

When applying a split to a table



#Abstract function definition
def func_split(value, splitter, index):

    x = value

    if splitter in value:
        y = x.split(splitter)

        if (len(x) + 1) >= index:
            x = y[index]
            
    return x

#Apply function
df['Column name'] = df['Column name'].apply(func_split, splitter="Bank", index=0)

The above "abstract function" includes not only a simple split, but also "whether the original character string contains the character" bank "in the first place" and "the index specified in the list of split results". It also includes the process of checking "whether there can exist".

Furthermore, if the above check is rejected, the value before splitting is returned as it is.

So, strictly speaking, it is not simply the same as field_value = field_value.split ("bank ") [0], but I think that it is normal to incorporate such consideration when using it in practice.

Apply a function to a field

eh? Isn't it better to incorporate that error control and field as well? You there who thought.

You're right. In that case, set the above func_split in the custom logic field of the relevant field, and then apply the function as follows.

When applying a split (with error control) to a field


#Apply function
field_value = func_split(field_value, "Bank", 0)

that's all!

How was it?

If you have any questions, please leave a comment on this article or contact us via DM on Twitter.

Recommended Posts

IQ Bot Custom Logic: Split Application (Apply to Table, Include Error Control)
IQ Bot Custom Logic Basic Key
IQ Bot Custom Logic: Delete the last n rows of the table
IQ Bot Custom Logic: Fixed Value Assignment
IQ Bot Custom Logic Related Processing Summary
IQ Bot Custom Logic: Split (extracts only bank and branch names from account information)
IQ Bot Custom Logic (Python): Streamline exclusions in loops
IQ Bot Custom Logic: Correcting common reading habits on dates
IQ Bot Custom Logic (Python): Efficient replacement process in a loop