Transpose columns into rows

fclavert
fclavert Registered Posts: 8 ✭✭✭✭

Dear dataiku community,

question from a non-developer: there is a processor to transform rows into columns. The thing is that I would like to do the opposite, as openrefine allows to do it. I have not found a processsor that fit that need.

Best,

F. Clavert

Answers

  • tim-wright
    tim-wright Partner, L2 Designer, Snowflake Advanced, Neuron 2020, Registered, Neuron 2021, Neuron 2022 Posts: 77 Partner
    edited July 17

    @fclavert
    , I will admit that I don't know of a simple way to do this with a visual recipe (though one may exist). While you wait for others to respond here is a very simple python recipe that should give you what you are after.

    # -*- coding: utf-8 -*-
    import dataiku
    
    # Read recipe inputs
    input_dataset = dataiku.Dataset("input_dataset")
    input_dataset_df = input_dataset.get_dataframe()
    
    # Write recipe outputs
    transposed = dataiku.Dataset("transposed")
    transposed.write_with_schema(input_dataset_df.transpose())

    Here, "input_dataset" should be changed to match the name of your actual dataset. You might want to try with a small-ish dataset before throwing a large dataset at it.

  • fclavert
    fclavert Registered Posts: 8 ✭✭✭✭

    Thanks a lot. I will try. I think I nevertheless found a visual recipe that could work (pivot). I will try and, if I succeed, will come back here.

    Best.

  • tim-wright
    tim-wright Partner, L2 Designer, Snowflake Advanced, Neuron 2020, Registered, Neuron 2021, Neuron 2022 Posts: 77 Partner

    @fclavert
    so first off, I feel like a complete dolt. Not having used the Transpose recipe I jumped straight to finding a solution. It just dawned on me that transpose rows to columns should be the same as columns to row. (transpose means to make rows columns and vice-versa)

    Using the Transpose calculation is not particularly intuitive (at least to me). But I found the following would allow me to transpose my data.

    1. Use the "Transpose Rows into Columns" but Specify a NONEXISTENT column (something like fake_column). That gives me a warning but will make all the columns rows and vice versa.

    2. Delete and rename columns as you see fit.

    -Tim

Setup Info
    Tags
      Help me…