I have two tables -Source and Target,in Target I want to update values for one column randomly

Options
pphanireddy007
pphanireddy007 Registered Posts: 3

I have two tables -Source and Target,in Target I want to update values for one column randomly from source table

Answers

  • Alexandru
    Alexandru Dataiker, Dataiku DSS Core Designer, Dataiku DSS ML Practitioner, Dataiku DSS Adv Designer, Registered Posts: 1,209 Dataiker
    edited July 17
    Options

    Hi @pphanireddy007
    ,

    You can use a code recipe in this case:

    import dataiku
    import pandas as pd, numpy as np
    from dataiku import pandasutils as pdu
    
    # Read recipe inputs
    dataset_1 = dataiku.Dataset("airline_stocks_prepared")
    df1 = dataset_1.get_dataframe()
    dataset_2 = dataiku.Dataset("airline_stocks")
    df2 = dataset_2.get_dataframe()
    
    
    np.random.seed(123)  # for reproducibility
    df2['random_value'] = np.random.choice(df1['column_name'], size=len(df2))
    
    
    # Write recipe outputs
    result = dataiku.Dataset("result")
    result.write_with_schema(df2)
    
Setup Info
    Tags
      Help me…