LAE

Welcome to the LAE community!  Please feel free to start a discussion in the discussion tab or join in a conversation.

Discussions

Members

Resources

Events

 View Only
  • 1.  Separate data into two fields, first name and last name.

    Employee
    Posted 08-20-2014 06:27

    Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.

    Originally posted by: sree

    Hi,

    I have a Full Name( DINO DELUCA) and i need to Separate the data into two fields, first name(DINO) and last name(DELUCA)
    Can any one share the node to be used with the syntax

    Regards,
    Sree


  • 2.  RE: Separate data into two fields, first name and last name.

    Employee
    Posted 08-20-2014 06:39

    Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.

    Originally posted by: ejones

    Try splitting the field on spaces.
    a = 'Full Name'.split(" ")
    emit str(a[0]) as "First Name"
    emit str(a[1]) as "Last Name"

    disclaimer: I did not test the above code so there may be a syntax error in it. Let me know if you find an issue with it.


  • 3.  RE: Separate data into two fields, first name and last name.

    Employee
    Posted 08-22-2014 21:13

    Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.

    Originally posted by: andycooper

    The attached graph provides both a simple text split example and also a more complex date/time split example.

    Split.brg


  • 4.  RE: Separate data into two fields, first name and last name.

    Employee
    Posted 08-27-2014 03:45

    Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.

    Originally posted by: gauravdb

    Hi Guys,

    I have a similar question so I am posing in same post.

    I have some data stored as string as this::

    "Name":"ABC","Age":20","Gender":"M"
    "Name":"XYZ","AGE":30","Gender":"F"

    And I am looking to separate them as individual attributes with the values. So the Output I am expecting should look like this:

    Name Age Gender
    ABC 20 M
    XYZ 30 F

    Is there a way we can do it ?

    Thanks
    GK


  • 5.  RE: Separate data into two fields, first name and last name.

    Employee
    Posted 08-27-2014 04:05

    Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.

    Originally posted by: Tim Meagher

    Hi,

    I think in your case what you would likely want to do is split up the individual key value pairs - similar to the mechanism suggested previously.
    Then, just output these as data fields, with a new record per key/value pair.
    After this, you can run the data through the Pivot - Data to Names node to turn the keys into field names where the values would then become the values for those fields.

    I've shown how to do this in the attached graph.

    If you know the exact number and ordering of the key value pairs, you could just parse and write the field values to the known column names.
    However, in the attached example, I've assumed neither the name or the number of these pairs is known in advance, so it will just output as many as it sees per row.
    The Pivot - Data to Names node then uses a "Union" on the NameSet parameter to ensure that if some records have more or less key/value pairs, that all are output for all of the records.

    The main pieces used for this graph are the split operator, mentioned previously, the "do output" operator, which allows you to write multiple output records for a single input record in a filter/agg etc node, and the use of the Pivot - Data to Names node.

    For more information on how the do output operator can be used generally, consult the BRAINScript help, under the section "Output Related".
    For more information on how to configure the Pivot - Data to Names node, consult the node help for the node.

    Hope this helps,

    Tim.
    Attachments:
    SplitAndPivot.brg


  • 6.  RE: Separate data into two fields, first name and last name.

    Employee
    Posted 08-27-2014 06:36

    Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.

    Originally posted by: gauravdb

    Thanks a lot Tim.

    just one more quick query please,

    As you can see from my data that I have double quotes in it. But within that data I have some text that I want to replace/remove. I know I can use a replace or regexSubstitution to do that BUT the problem is that the text I want to remove is also in double quotes plus there is a colon next to it.

    Let me give an example

    "Name":"ABC","Age":20","Gender":"M", "REMOVEIT:","Profession":"Doctor"
    "Name":"XYZ","AGE":30","Gender":"F", "REMOVEIT:","Profession":"Teacher"

    Here I would like to remove the word REMOVEIT: plus the double quotes on its either sides. This pattern is repeating itself in the every row. I know we can use a backslash to remove a double quote but here the scenario is bit different.

    Can you help me on that please

    Thanks
    GK


  • 7.  RE: Separate data into two fields, first name and last name.

    Employee
    Posted 08-27-2014 06:44

    Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.

    Originally posted by: ejones

    This is confusing me so I'm not sure I understand the question.
    Once you read the data in from a CSV file using the "Delimited File" node, the double quotes would also be removed. You will be left with a field that has the value REMOVEIT: including the colon but without the quotes. If you want that removed from the field you would just exclude the field in a Filter node. Or if you want to remove the colon you would use the replace() function as you said you already understood.