Want to Stop Rebuilding "Expensive" Parts of your Flow? Explicit Builds are the Answer!READ MORE

Writing multiple files into a folder

Ksawery
Level 1
Writing multiple files into a folder

Hi,

I would like to write multiple files into a Dataiku folder. Unfortunately, when I do the following, I am getting an error:

data_df = dataiku.Dataset("data")
data = data.get_dataframe()

output = dataiku.Folder("2jiawe32x")

for cnt in data.country.unique():
 df = data[data.country == cnt]
 output.upload_stream(str(cnt), df)

 

The error that I am getting is:

The truth value of a DataFrame is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().

 

Is there any workaround? 

0 Kudos
1 Reply
JuanE
Dataiker
Dataiker

This happens because you should not directly pass the pandas dataframe as the second argument to the upload_stream method:

https://doc.dataiku.com/dss/latest/python-api/managed_folders.html#dataiku.Folder.upload_stream

Thus, you could do something like:

for cnt in data.country.unique():
    df = data[data.country == cnt]
    output.upload_stream(str(cnt) + ".csv", df.to_csv())

 

0 Kudos