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
Answers
-
Turribeach Dataiku DSS Core Designer, Neuron, Dataiku DSS Adv Designer, Registered, Neuron 2023 Posts: 2,088 Neuron
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.