Options

how to shift columns/rows of Example Set ?

GofmanGofman Member Posts: 3 Learner I
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!

Best Answer

Answers

  • Options
    lionelderkrikorlionelderkrikor Moderator, RapidMiner Certified Analyst, Member Posts: 1,195 Unicorn
    Hi @Gofman,

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

    Hope this helps,

    Regards,

    Lionel
  • Options
    varunm1varunm1 Moderator, Member Posts: 1,207 Unicorn
    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.


    Regards,
    Varun
    https://www.varunmandalapu.com/

    Be Safe. Follow precautions and Maintain Social Distancing

  • Options
    BalazsBaranyBalazsBarany Administrator, Moderator, Employee, RapidMiner Certified Analyst, RapidMiner Certified Expert Posts: 955 Unicorn
    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
  • Options
    GofmanGofman Member Posts: 3 Learner I
    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?






  • Options
    varunm1varunm1 Moderator, Member Posts: 1,207 Unicorn
    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?
    Regards,
    Varun
    https://www.varunmandalapu.com/

    Be Safe. Follow precautions and Maintain Social Distancing

  • Options
    sgenzersgenzer Administrator, Moderator, Employee, RapidMiner Certified Analyst, Community Manager, Member, University Professor, PM Moderator Posts: 2,959 Community Manager
    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
Sign In or Register to comment.