Delete the nth row

Luisa
Luisa Registered Posts: 3

Hello, I would like to delete the nth row of my output dataset, yet I don't know how to do that..

Answers

  • Turribeach
    Turribeach Dataiku DSS Core Designer, Neuron, Dataiku DSS Adv Designer, Registered, Neuron 2023 Posts: 2,161 Neuron

    Hi. Can you explain your requirement with a bit more detail? Deleting sounds like filtering to me. Why can’t you filter the row out? Please give sample data if it is data driven. Thanks

  • louisbarjon
    louisbarjon Dataiker, Dataiku DSS Core Designer, Dataiku DSS Adv Designer, Registered Posts: 9 Dataiker
    edited July 19

    Can you define a sorting order on your dataset ? If yes you can use the sort recipe that let's you create a row_number column. Then you can easily remove this row in a prepare recipe.
    If you cannot sort your dataset, the only way I see is first using a python code recipe to generate the row_number

    import dataiku
    import pandas as pd
    
    input_dataset = dataiku.Dataset("your_input_dataset")
    df = input_dataset.get_dataframe()
    
    # Add a row number column
    df['row_number'] = range(1, len(df) + 1)
    
    # Write the output dataset
    output_dataset = dataiku.Dataset("your_output_dataset")
    output_dataset.write_with_schema(df)
    
    

Setup Info
    Tags
      Help me…