Survey banner
The Dataiku Community is moving to a new home! We are temporary in read only mode: LEARN MORE

Converting Python script to Python Recipe to output multiple files locally

Jtbonner86
Level 2
Converting Python script to Python Recipe to output multiple files locally

Hi, 

I have a basic python script that reads in a file and splits this file (based on a supplier) into multiple CSV file and stores them in a dataiku managed folder. 

 

I now want to convert this notebook into a python recipe but am unable to do so as it looks as if the recipe is looking for a singular output.. Help....

 

Code in notebook;

import dataiku
import pandas as pd

folder_name = "Suppliers"
input_dataset = dataiku.Dataset("OOB_2301")

handle = dataiku.Folder(folder_name)

df = input_dataset.get_dataframe()

unique_sup = df['SUPPLIER'].unique()

for sup in unique_sup:
sub_df = df.loc[df['SUPPLIER'] == sup]
name = str(sup) + "_output.csv()"
with handle.get_writer(name) as w:
w.write(df.to_csv().encode('utf-8'))


Operating system used: Windows


Operating system used: Windows

0 Kudos
1 Reply
Turribeach

Please always post code using the code block (the </> icon in the toolbar) as otherwise the padding is lost and you probably know Python code can not run without the proper padding. 

There should be no reason as to why your code doesn't work in a recipe. Please post the error/issue/behavior that you see as "unable to do so" doesnt' really say much. 

0 Kudos

Labels

?
Labels (4)

Setup info

?
A banner prompting to get Dataiku