how to shift columns/rows of Example Set ?

Gofman
Gofman New Altair Community Member
edited November 2024 in Community Q&A
Hi,
I would like to shift the columns of a given data set right\left much like the "shift" operator of pandas for dataframes.
Is there any elegant way of doing so instead of renaming the columns names?

Thanks!
Tagged:

Best Answer

  • BalazsBaranyRM
    BalazsBaranyRM New Altair Community Member
    Answer ✓
    No, there is no single operator.
    Also, you can always use the Python scripting operator if you already have a solution in Python.

Answers

  • lionelderkrikor
    lionelderkrikor New Altair Community Member
    Hi @Gofman,

    If I good understand what you want to do, you can use the Reorder Attributes operator.

    Hope this helps,

    Regards,

    Lionel
  • varunm1
    varunm1 New Altair Community Member
    Adding to @lionelderkrikor post, you can create dummy columns with null values (similar to shift) using generate attribute operator with a value NaN and then use reorder attributes to set these dummy columns at the start of data frame.


  • BalazsBaranyRM
    BalazsBaranyRM New Altair Community Member
    Hi @Gofman,

    so you would copy the value from Col2 to Col3, then from Col1 to Col2, then fill Col1 with missings.

    Reorder Attributes would help you in sorting the columns for Loop Attributes.
    Then in Loop Attributes you would use Rename to the appropriate name, or Generate Attributes.

    Regards,
    Balázs
  • Gofman
    Gofman New Altair Community Member
    Just like @BalazsBarany said, I want to shift all values of Col1 to Col2 and so on (Col 2 to Col 3..), thus "Reorder Attributes" does not help me much.

    Is there any other way of doing so without using loops? something more like a single operator?






  • varunm1
    varunm1 New Altair Community Member
    edited February 2020
    Hello @Gofman

    Yep, that is why I was talking about generate attribute before reorder. So, incase of pandas shift the columns are shifted places and a null column is added at the start. So, if you want to shift the colums by 2 periods, you can generate 2 columns with null values and reorder the attributes after that by placing these null columns infront of the original columns. If you want to rename the col names you can do that using rename operator as well. @BalazsBarany informed same but with loops

    I know this is not a direct way, but if you dont want to use loops, I guess this might work.

    Do you need a sample process?
  • BalazsBaranyRM
    BalazsBaranyRM New Altair Community Member
    Answer ✓
    No, there is no single operator.
    Also, you can always use the Python scripting operator if you already have a solution in Python.

  • sgenzer
    sgenzer
    Altair Employee
    hi @Gofman welcome to the community :smile: One key thing to understand about RapidMiner is that the ordering of the attributes in the Results view is purely aesthetics and can change all the time depending on what the last operator was. It is not like a database where the order remains constant. There are just not many situations where the order matters. Even the operator "Reorder Attributes" is basically a "vanity" operator to make things pretty when you see them.

    Scott